How to delete data from sql with pdo?

后端 未结 1 1310
自闭症患者
自闭症患者 2020-12-11 09:06

Hello I have search the web all day trying to find example of deleting data when I use pdo but all i found its MySQL and MySQLi and I am stuck i can\'t see what I am missing

相关标签:
1条回答
  • 2020-12-11 09:20

    I would start with something like this:

        $con =  new PDO( "mysql:host=".$dbHost.";"."dbname=".$dbName, $dbUsername, $dbUserPassword); 
        $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        $sql = "DELETE FROM `table` WHERE id = ?";        
        $q = $con->prepare($sql);
    
        $response = $q->execute(array($id));                
    
    0 讨论(0)
提交回复
热议问题