开发者

Debugging MySQL Insert Failure When No Error Is Returned to PHP

开发者 https://www.devze.com 2023-01-14 14:00 出处:网络
I\'m testing some new code to insert into a MySQL database from using PHP.The test $stmt->execute();

I'm testing some new code to insert into a MySQL database from using PHP. The test

$stmt->execute();
if ($stmt->errorCode() != 0)
{
    $arr = $stmt->ErrorInfo();
    throw new Exception('SQL failure:'.$arr[0].':'.$arr[1].':'.$arr[2]);
}
开发者_JS百科

It threw a number of errors that I fixed one by one. Finally it dropped through, but nothing was written to the table. Is there any other test I can do or a log I could set up to see what the problem is? MySQL is running locally on my development PC.

Thanks for any help, Curt

P.S. The similar posting six months ago didn't suggest any further means of debugging that I could see.


I found an answer to my question, but am hoping for a better one. I copied the sql statement to phpMyAdmin SQL query window, substituted literals for all the variables, and ran it. I got an error 1426 IIRC, which deals with a foreign key mismatch. I got that error because the foreign key table was not innodb while the others were. Once I made that change in the DB, the query ran correctly. You would think that error would be returned in errorCode.


You can activate MySQL's General Query Log and keep an eye on that log file.

0

精彩评论

暂无评论...
验证码 换一张
取 消