
据我所知,已在PHP
5.3中
PDO_MYSQLND替换
PDO_MYSQL。令人困惑的是,名字仍然是
PDO_MYSQL。因此,现在ND是MySQL +
PDO的默认驱动程序。
总体而言,一次执行多个查询需要:
使用执行
$db = new PDO("mysql:host=localhost;dbname=test", 'root', '');// works regardless of statements emulation$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);$sql = "DELETe FROM car; INSERT INTO car(name, type) VALUES ('car1', 'coupe'); INSERT INTO car(name, type) VALUES ('car2', 'coupe');";try { $db->exec($sql);}catch (PDOException $e){ echo $e->getMessage(); die();}使用语句
$db = new PDO("mysql:host=localhost;dbname=test", 'root', '');// works not with the following set to 0. You can comment this line as 1 is default$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);$sql = "DELETe FROM car; INSERT INTO car(name, type) VALUES ('car1', 'coupe'); INSERT INTO car(name, type) VALUES ('car2', 'coupe');";try { $stmt = $db->prepare($sql); $stmt->execute();}catch (PDOException $e){ echo $e->getMessage(); die();}一张纸条:
使用模拟的准备好的语句时,请确保已在DSN中设置了正确的编码(反映了实际的数据编码)(自5.3.6起可用)。否则,如果使用某种奇数编码,则可能会有少量的SQL注入。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)