user576820
user576820

Reputation: 1347

PHP PDO-MySQL prepared statement with multiple values

I know you can't use the " character, tried ` instead and that didn't work, any ideas?

$sql = $db->prepare('INSERT INTO testDB VALUES(`$title`,`$bodytext`,`$created`)');

Upvotes: 0

Views: 1063

Answers (1)

Emil Vikström
Emil Vikström

Reputation: 91942

Try this:

$sql = $db->prepare('INSERT INTO testDB VALUES(?, ?, ?)');
$sql->execute(array($title, $bodytext, $created));

What I did was removing the variables from the SQl query and replaced them with ? as placeholder. You only bind values to the statement at execution time.

The way you tried to do it was no different from using regular SQL queries.

Upvotes: 3

Related Questions