0

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

user2710234
  • 3,177
  • 13
  • 36
  • 54

2 Answers2

1

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.

The Humble Rat
  • 4,586
  • 6
  • 39
  • 73
  • i know the connection is established because i am running code before what i posted which is working fine – user2710234 Nov 27 '14 at 10:53
  • @user2710234 have a look here to see if this helps http://stackoverflow.com/questions/11519966/pdo-sql-state-00000-but-still-error. Also try running the query in navicat, mysql workbench, phpmyadmin or similar to ensure it works correctly. – The Humble Rat Nov 27 '14 at 10:55
  • @user2710234 Also it seems that `ERROR: 00000` actually means the insert was successful. Have you checked your DB to make sure the record has not been added. – The Humble Rat Nov 27 '14 at 10:57
0

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.

Allmighty
  • 1,499
  • 12
  • 19