【发布时间】:2012-07-16 05:23:54
【问题描述】:
谁能解释一下原因
$sql->execute($params);
返回FALSE,而
print $pdo->errorCode();
print_r($pdo->errorInfo());
都返回SQLSTATE00000,这意味着根据文档成功?它是一个INSERT,实际上并没有向数据库中插入任何内容……那么,为什么我会收到来自SQLSTATE 的成功消息?
如果有帮助,这就是代码...
$sql = $pdo->prepare("
INSERT INTO user (
username, fname, pass, salt, email,
loc_id_home, country_id_home, region_id_home,
cont_id_home, timestamp_reg, timestamp_upd, timestamp_lastonline,
online_status, gender, birthdate
)
VALUES (
:username,:fname,:pass,:random_salt,:email,
:loc_id_home,:country_id_home,:region_id_home,
:cont_id_home,'".time()."','".time()."','".time()."',
1,:gender,:birthdate)
");
$params=array(
':username'=>$username,
':fname'=>$fname,
':pass'=>$pass,
':random_salt'=>$random_salt,
':email'=>$email,
':loc_id_home'=>$loc_id_home,
':country_id_home'=>$country,
':region_id_home'=>$region,
':cont_id_home'=>$continent,
':gender'=>$gender,
':birthdate'=>$birthdate
);
$sql->execute($params);
print $pdo->errorCode();
print_r($pdo->errorInfo());
【问题讨论】:
-
你在 $params 中存储了什么?请粘贴它..
-
有一个bug。也许这是一个原因。
-
@JalpeshPatel:谢谢,我已经发布了代码...
-
创建prepared statement后还需要勾选
PDOStatement::errorCode意思$sql->errorCode()。 -
我知道它很旧,但我建议使用 $sql->errorInfo();而不是 $pdo->errorInfo();
标签: php mysql sql database pdo