2
votes

i have one question about PDO::exec() and bindparams.

exec($sql) return # of affected rows. but u can bind params to exec() like prepare->bindParams()->execute()?

If answer is no, u can get affected rows with any trick in prepare->bindParams()->execute()? (I understand execute only returns true/false)

Thanks for help.

1
I know all about this topic and I still have trouble understanding the question at hand. Could you please fix the grammatical errors and clarify? - Tyler Crompton
PDO::exec() is the equivalent of mysql_query(), except it doesn't return result handles. It doesn't support binding, because its main argument is a raw sql string. - Marc B

1 Answers

2
votes

You can get affected rows from PDOStatement object after execute it:

$statement = $pdo->prepare($query);
$statement->bindParam(':param1', $value1);
$result = $statement->execute();
$affectedRows = $statement->rowCount();