Try / catch in mysqli

后端 未结 3 1066
北海茫月
北海茫月 2021-01-17 22:00

I\'m following an OOP mysqli course. When connecting to the database, they use the following script:

$db = new mysqli(\"host\", \"user\", \"password\", \"dat         


        
3条回答
  •  借酒劲吻你
    2021-01-17 22:19

    Are you asking about what's the different with $db->connect_error and try/catch?

    $db->connect_error mostly for the errors which we already knew (username incorrect, etc.)

    and try/catch is about system level, once an error occur,

    PHP will search for the nearest try/catch block,

    once it catch something, PHP will still continue like nothing happened before,

    but if you don't have any try/catch block and set_exception_handler() too,

    PHP will just stop by the error.

提交回复
热议问题