Kelly Larsen
Kelly Larsen

Reputation: 973

pdo insert without variables

I'm trying to insert a new record into a table that contains only an auto number primary key using the following code,

$pdo_conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$sqla = "insert into tbl_gen (gen_sk) values (null)";
$qa = $pdo_conn->prepare($sqla);
$qa->execute();

is this the right way to go about it? running the sql command in mysql workbench does the job, I'm just feeling like maybe I'm using pdo the wrong way.

Upvotes: 1

Views: 443

Answers (1)

Marc B
Marc B

Reputation: 360702

Prepared statements are intended to be re-used. If you're just doing a simple one-shot query, then use $pdo->exec() instead. This avoids the overhead of preparing the statement, and just simply "does it".

But regardless, there's nothing "wrong" with how you're going about it.

Upvotes: 3

Related Questions