PDO SQL状态“00000”但仍然报错? [英] PDO SQL-state "00000" but still error?

查看:1118
本文介绍了PDO SQL状态“00000”但仍然报错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP PDO。查询正确时错误号码'00000'

任何人都可以解释为什么



Can anybody explain why

$sql->execute($params);

返回 FALSE ,而

print $pdo->errorCode();
print_r($pdo->errorInfo());

两者都返回 SQLSTATE 00000 ,这意味着根据文档成功?它是一个 INSERT ,没有什么是实际插入到数据库...所以,为什么从 SQLSTATE

both return SQLSTATE 00000, which means according to the documentation success? It is an INSERT and nothing is actually being inserted into the database... so, why do I get a success message from SQLSTATE?

如果有帮助,这是代码...

In case it helps, this is the code...

$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());


推荐答案

这是因为$ pdo-> errorInfo到成功执行的最后一条语句。因为$ sql-> execute()返回false,那么它不能引用那个语句(无论是无关还是以前的查询)。

It is because $pdo->errorInfo() refers to the last statement that was successfully executed. Since $sql->execute() returns false, then it cannot refer to that statement (either to nothing or to the query before).

至于为什么$ sql- > execute()返回false,我不知道...你的$ params数组或数据库连接有问题。

As to why $sql->execute() returns false, I don't know... either there is a problem with your $params array or with your database connection.

PDO::errorCode — Fetch the SQLSTATE associated with the last operation on the database handle

这篇关于PDO SQL状态“00000”但仍然报错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆