PHP-PDO-MySQL-Class icon indicating copy to clipboard operation
PHP-PDO-MySQL-Class copied to clipboard

Statement Success Or Not

Open dimaslanjaka opened this issue 6 years ago • 3 comments

how can i determine query are success or not ? some like if ($execute = DB->query(blablabla)){} ?

dimaslanjaka avatar Mar 02 '19 05:03 dimaslanjaka

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
}

lincanbin avatar Mar 02 '19 06:03 lincanbin

@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 
}

marcus-hiles avatar Mar 27 '19 11:03 marcus-hiles

okay guys i understand, thank your help sweety

dimaslanjaka avatar Mar 29 '19 09:03 dimaslanjaka