user2710234
user2710234

Reputation: 3225

PDO Insert SQL not executing with no errors

I am running this code:

$stmt = $pdo_conn->prepare("INSERT into ticket_updates (ticketnumber, notes, datetime, contact_name, contact_email, customer, internal_message, type) values (:ticketnumber, :notes, :datetime, :contact_name, :contact_email, :customer, :internal_message, :type) ");
            $stmt->execute(array(':ticketnumber' => $ticketnumber, 
            ':notes' => $TicketSummary, 
            ':datetime' => date("Y-m-d H:i:s"),  
            ':contact_name' => $Ticket_ContactName, 
            ':contact_email' => $Ticket_ContactEmail, 
            ':customer' => 'Y', 
            ':internal_message' => 'N', 
            ':type' => 'update'));

all the table columns exist and are correct but its not getting past this point

i tried a var_dump($stmt); but get nothing

Upvotes: 0

Views: 94

Answers (2)

The Humble Rat
The Humble Rat

Reputation: 4696

Use the following to verify the connection is established correctly

try
{
    $dbh = new PDO("mysql:host=xxxxxxxxxxxx;dbname=streaming", "xxxx", "xxxx");
}
catch (Exception $e)
{
    throw new Exception( 'Something really gone wrong', 0, $e);
}

You can also output errors when you execute like so

$sth->execute() or die(print_r($sth->errorInfo(), true));

Finally you may also need to enable errors on the page, so place this in the header of your page or at the very top if it is a single page:

error_reporting(-1);

The minus 1 means that it will print all errors.

Until you have discovered the error it is very hard to diagnose the issue further, but the issue likely falls down to either the connection to the database or how you have formed the parameter array.

Upvotes: 1

Allmighty
Allmighty

Reputation: 1519

Add error reporting to your pdo:

$pdo_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);

before executing the insert command.

Then on the insert command, output your errors

$stmt->execute(array(':ticketnumber' => $ticketnumber, ':notes' => $TicketSummary, ':datetime' => date("Y-m-d H:i:s"),
':contact_name' => $Ticket_ContactName, ':contact_email' => $Ticket_ContactEmail, ':customer' => 'Y', ':internal_message' => 'N', ':type' => 'update')) or die("ERROR: " . implode(":", $pdo_conn->errorInfo()))

This should give you an indication of what is wrong and why things are not executing as expected.

Upvotes: 0

Related Questions