Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Old but new again - Debugging PDO prepared statements

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
Over the past few years I've migrated to PDO use within PHP and for the most part the results are successful. However, there are times when the opposite is true.
After spending the better part of several days researching an failing UPDATE I thought I would ask here to find out what others are doing to debug these unknown errors.
Im using MariaDB on a WHS server managed with cPanel.

My MySQL logs are turned on.

I'm using the ^ALL declarative with PHP.
error_reporting(E_ALL ^ E_NOTICE);

I include the errorreporting attribute after opening the DB:
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

and everything else I regularly use or find via research.

My symptom is this:
Open DB,
Construct SQL Query with tokens,
Prepare the SQL statement,
Bind the variable values,
execute the query,
intercept errors,

$t0 = $pdo->prepare("$sql");
$t0->bindValue(':coordinator',$coordinator);
try { $t0->execute(); }
catch (PDOException $e) { db_die("$e->getMessage()); }

and the result is NO failures, return code of 0, no error message, no errors written to log files in /var/log/mysql/sitename/*

and seeing how I'm trying to show everything here - this is the SQL statement.

UPDATE ss_tasks SET
coordinator = :coordinator,
coordinator_id = :coordinator_id,
sched_date = :sched_date,
sched_time = :sched_time,
todo_description = :todo_description,
todo_priority = :todo_priority
WHERE task_id = :task_id
LIMIT 1

Honestly, I HOPE someone finds a simple error that my eye/brain simply overlooked.

Thanks for any advice,suggestions,etc/ [banghead]
 
If no failure codes or errors are coming back it would stand to reason the Update is running correctly. Whether it updates something or not is a different question.

An Update query would not issue an error if it cannot update anything given the update query. It would simply return a normally benign "0 Rows Affected" message, which still counts a successful query.

If your update is not actually updating anything, your next option would be to output your actual query with the values substituted in, and then checking that your conditions are actually producing a row to be updated. In your case, is the task_id sent to the query one that actually exists so a row is found that can be updated.







----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top