Native Coder Native Coder - 3 months ago 22
MySQL Question

PDO throws an uncaught exception halfway through my MySQL statement

I've had this issue before and can't for the life of me figure out what keeps causing it. I have a PDO statement that looks like this

$fields = "
`ProgramName` = :programName,
`TotalUnits` = :totalUnits,
`UnitCost` = :unitCost,
`Description` = :description,
`CreationDate` = NOW()

$description = isset($_POST['description']) ? $_POST['description'] : null;

$insertProgram = $dbHandle -> prepare("INERT INTO `Programs` SET $fields");
$insertProgram -> bindParam(':programName', $_POST['programName'] );
$insertProgram -> bindParam(':totalUnits' , $_POST['totalUnits'] );
$insertProgram -> bindParam(':unitCost' , $_POST['unitCost'] );
$insertProgram -> bindParam(':description', $description );
$insertProgram -> execute();

The Error is the generic old "

Syntax error or access violation: 1064...check the manual for the correct syntax to use near.

`ProgramName` = ?,

        `TotalUnits` = ?,

        `Uni' at line 1

See where it cuts off "UnitCost", even thought it's a perfectly formatted string in $fields? What in the world causes this? I'm using back-ticks on all of my column names...


I can't reproduce your error.

For a query like this

INERT into test SET foo='11111111111111111111111111111111111', bar='2222222222222222222222222222222';

it is giving me the error

the right syntax to use near 'INERT into test SET foo='11111111111111111111111111111111111', bar='222222222222' at line 1

which conforms to my experience when mysql is showing the query part that's immediately following the problem part.

And the answer to your question "Why mysql does cut the original query at all" is fairly simple: the query could be up to 2 megabytes long or even more. And you apparently don't want an error message of that size.