PHP-PDO-MySQL-Class
PHP-PDO-MySQL-Class copied to clipboard
Statement Success Or Not
how can i determine query are success or not ? some like if ($execute = DB->query(blablabla)){} ?
It returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE , DELETE , or INSERT.
if ($DB->query("INSERT balabalabalabala") > 0) {
// success
} else {
// not
}
@dimaslanjaka in addition to @lincanbin's answer, you can put your execute statement in a try catch block, so if there's any execution error error, you can detect it. Eg.
try {
if ($DB->query("INSERT balabalabalabala") > 0) {
// success
} else {
// not
}
} catch (PDOException $e) {
//codes to run upon getting execution error, goes here
}
okay guys i understand, thank your help sweety