Chris Chris - 2 months ago 15
MySQL Question

PDO SQL-state "00000" but still error?


Possible Duplicate:

PHP PDO. error number ‘00000’ when query is correct




Can anybody explain why

$sql->execute($params);


returns
FALSE
, whereas

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


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

Answer

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).

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