0

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]);
}

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.

1
  • $stmt is an instance of PDOStatement? Commented Aug 29, 2010 at 21:18

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

I turned on the log and I see activity, but not when I execute my problem statement. Is it the case that MySQL sometimes doesn't report errors?
Well I know of at least one error that it doesn't report. I failed to set the primary key field to auto-increment and didn't supply a value on the INSERT as would be the case had I done so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.