Пример #1
0
 public function delete($tablename, $condition)
 {
     //delete data
     $dbconfig = new DBconfig();
     $host = $dbconfig->host();
     $user = $dbconfig->username();
     $pwd = $dbconfig->pwd();
     $db = $dbconfig->db();
     try {
         $conn = new PDO("mysql:host={$host};dbname={$db}", $user, $pwd);
         // set the PDO error mode to exception
         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $sql = "DELETE FROM " . $tablename . " WHERE (" . $condition . ")";
         // use exec() because no results are returned
         $conn->exec($sql);
         return true;
     } catch (PDOException $e) {
         echo $sql . "<br>" . $e->getMessage();
         return false;
     }
     $conn = null;
 }