Domanda

Coming from Powerbuilder and moving into PHP/MySQL. We often use SQLCA.SQLCODE to check if our SQL statements have been successful. Is there something similar for MySQL?

IF SQLCA.SQLCODE = 0 THEN
  // do something
ELSE
  // do something else
ENDIF

As far as I can tell mysqli_errno seems to be the most similar though I'm not sure if it's what we're looking for.

If not, could someone point me out as to how this could/should/would be done?

È stato utile?

Soluzione

you do not need to use errno. Checking mysqli_query() result is sufficient:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

so (mind the comparision operator!)

if( mysqli_query("....") !== false ) {
    // ok
} else {
    // zonk
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top