debugging

Show MySQL warnings after query

Snippet

When a query has run, a number of warnings may have occurred that didn't stop the query from running, but may be of concern. Use "SHOW WARNINGS [LIMIT n]" to display the warnings and see what might have gone wrong in the query.

mysql> SELECT name, addr1, addr2, city, state, FROM_UNIXTIME(created_on) AS created FROM `orders` WHERE ...;
Empty set, 20180 warnings (0.02 sec)
 
mysql> show warnings limit 10;
+---------+------+---------------------------------------------------------+
| Level   | Code | Message                                                 |
+---------+------+---------------------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '2009-08-21 00:01:01' | 
| Warning | 1292 | Truncated incorrect DOUBLE value: '2009-08-26 00:01:01' | 
| Warning | 1292 | Truncated incorrect DOUBLE value: '2009-08-21 00:01:01' | 
| Warning | 1292 | Truncated incorrect DOUBLE value: '2009-08-26 00:01:01' | 

Print evaluated query string using ADODB/PHP

Snippet

After a parameterized querystring has been evaluated, but before the query has been run, print out the query string, using ADODB PHP library.

<?php
 
/*
 * include the ADODB library
 */
include('adodb.inc.php');
 
/*
 * Make a new connection to DB
 */
$mydb = &ADONewConnection('access');     
$mydb->PConnect('northwind');  
 
/*
 * filter input
 */
$shipto = $conn->qstr("John's Old Shoppe");
 
/*
 * generate SQL
 */
$sql = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";
$sql .= "values ('ANATR',2,".$mydb->FormatDate(time()).",?)";
 
/*
 *
 *
 * PRINT THE SQL BEFORE EXECUTING THE QUERY
 *
 *
 */
$mydb->debug = true;
 
if ($mydb->Execute($sql, $shipto) === false) print 'error inserting';
 
?>