如何为失败的sqlite插入生成基本CLI错误消息?

I'm using PHP for some simple shell scripting to convert existing data into SQLite tables on my local machine. However, when I run the scripts on the command line, I do not get errors even when the INSERT function clearly fails (i.e. the records aren't in the table when it's through). Is there an obvious solution to this?

The code below is a simplified version of what I'm using (which has more subloops, etc. which make it difficult to track down what exactly isn't being inserted in the tables). For example, if person's name has a newline char in it, it doesn't get inserted, but I have no error message to determine the problem. Also, I initially forgot to use the single quotes around the emp_name text field, and also did not get an error on the command line.

$db = new PDO('sqlite:mydatabase.sqlite');
$db->exec("CREATE TABLE employee_data (emp_id INTEGER, emp_name TEXT);");    
$db->beginTransaction();
foreach($people_data as $person) {
  $db->exec("INSERT INTO employee_data VALUES ('{$person->emp_id}', '{$person->emp_name}');");
}
$db->commit();
$db = NULL;

Thanks! Bryan

Thanks for using PDO!

PDO is silent by default. You might want to either enable Warnings mode or Exceptions mode using setAttribute, which will cause it to whine when you do something wrong. If you enable Warnings mode, then also make sure you can display those warnings, which can be done by the commands everyone else has posted.

If you'd rather do it manually, there are errorCode and errorInfo methods that you can check after each query, the use of which is documented on the error mode page I linked above.

check your error_reporting in php.ini in /etc/php5/cli (ubuntu/debian).

You should set error_reporting to proper level and display_errors to On. This can be done via:

ini_set('display_errors', 'on');
error_reporting(E_ALL & ~E_NOTICE);

You can add:

ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);

At the top of your script to enable error reporting.

Also in your php.ini file you can enable logging to a PHP error log file. This is probably the easiest approach with a CLI script so you can tail -f in another terminal.