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.
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.