由于某种原因,此自定义PDO类无法写入数据库。它只是悄然失败 - 没有抛出错误信息。一个非常相似的自定义PDO类(ReadPDO)非常适合从数据库中读取。生成的SQL语句在通过PHPMyAdmin查询数据库时工作正常。我已经仔细检查了用户权限,一切看起来都是有序的。
我怀疑我误解了某些事情的运作方式。有什么想法吗?
// Creates a write-only PDO, using config settings from inc_default.php
class WritePDO extends PDO{
public function __construct(){
//Pull global DB settings
global $db;
global $write_host;
global $write_username;
global $write_password;
try{
parent::__construct("mysql:dbname={$db};host={$write_host}", $write_username, $write_password);
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
}
}
private function updatePlayer(){
$conn = new WritePDO();
$sql = "UPDATE {$this->hvz_db}
SET
hvz_bitten ='{$this->hvz_bitten}',
hvz_died ='{$this->hvz_died}',
hvz_feedCode ='{$this->hvz_feedCode}',
hvz_status ='{$this->hvz_status}',
hvz_feeds ='{$this->hvz_feeds}',
hvz_lastFed ='{$this->hvz_lastFed}',
hvz_ozOpt ='{$this->hvz_ozOpt}',
hvz_parent ='{$this->hvz_parent}'
WHERE users_id ={$this->id}";
$query = $conn->exec($sql);
}
它吐出的SQL如下:
UPDATE hvz_2011_spring SET hvz_bitten ='', hvz_died ='', hvz_feedCode ='NOMNOM', hvz_status ='Human', hvz_feeds ='0', hvz_lastFed ='', hvz_ozOpt ='0', hvz_parent ='' WHERE users_id =1
答案 0 :(得分:1)
你确定sql是正确的吗?
exec不会发送任何错误消息。
尝试做var_dump($ conn-> errorInfo());在$ conn-> exec($ sql);
之后/埃米尔