Note that there are some explanatory texts on larger screens.

plurals
  1. POGet SQL Query and parameters from PDO prepared statement
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3754530/retrieve-or-simulate-full-query-from-pdo-prepared-statement">Retrieve (or simulate) full query from PDO prepared statement</a><br> <a href="https://stackoverflow.com/questions/7716785/get-last-executed-query-in-php-pdo">Get Last Executed Query in PHP PDO</a><br> <a href="https://stackoverflow.com/questions/11122573/pdo-debugging-view-query-after-bind">PDO Debugging - View Query AFTER Bind?</a> </p> </blockquote> <p>Using the <code>PDOException</code> class, I can get various info relating to a SQL error. One part lacking is the actual SQL query which caused the error. This is helpful in troubleshooting integrity constraint violation errors. Even if the full query with inserted parameters is not available, the prepared query along with the array passed by <code>execute()</code> would suffice as I can recreate the full query. Note that I currently do not use bindParam(), but pass all data using <code>execute()</code>.</p> <p>How can I view the actual query that caused the error? Thank you</p> <p>Error:</p> <blockquote> <p>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>website/accounts</code>, CONSTRAINT <code>fk_accounts_zipcodes1</code> FOREIGN KEY (<code>zipcodes_id</code>) REFERENCES <code>zipcodes</code> (<code>id</code>) ON DELETE NO ACTION ON UPDATE NO ACTION)<br />File Name: /var/www/main/components/com_upload/models/contacts.phpLine: 520<br />Time of Error: Monday October 15, 2012, 7:11:49 PDT</p> </blockquote> <p>SQL which caused error:</p> <blockquote> <p>INSERT INTO accounts (id, sites_id, name, address, cities_id, zipcodes_id, phone, fax, date_created, date_modified, record_status, vertical_markets_id,priority_id,roles_id) VALUES (:id,123,:name,:address,:cities_id,:zipcodes_id,:phone,:fax,NOW(),NOW(), "active" ,:vertical_markets_id,:priority_id,:roles_id)</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload