Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

calin at NOSPAM dot softped dot com
9 years ago
PDO::eval() might return `false` for some statements (e.g. CREATE TABLE) even if the operation completed successfully, when using PDO_DBLIB and FreeTDS. So it is not a reliable way of testing the op status.

PDO::errorInfo() can be used to test the SQLSTATE error code for '00000' (success) and '01000' (success with warning).

<?php
function execute(PDO $conn, $sql) {
$affected = $conn->exec($sql);
if (
$affected === false) {
$err = $conn->errorInfo();
if (
$err[0] === '00000' || $err[0] === '01000') {
return
true;
}
}
return
$affected;
}
?>

PDO::errorInfo(): http://php.net/manual/en/pdo.errorinfo.php
List of SQLSTATE Codes: http://www-01.ibm.com/support/knowledgecenter/SSGU8G_11.70.0/com.ibm.sqls.doc/ids_sqs_0809.htm

<< Back to user notes page

To Top