mysqli异常类

(PHP 5, PHP 7, PHP 8)

简介

mysqli异常类

类摘要

mysqli_sql_exception extends RuntimeException {
/* 属性 */
protected string $sqlstate ;
/* 继承的属性 */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
}

属性

sqlstate

出现错误的sql状态

User Contributed Notes

cnlyzy at qq dot com 12-May-2017 08:11
<?php
mysqli_report
(MYSQLI_REPORT_STRICT);
try {
   
$mysqli = new mysqli('127.0.0.1','uesr','password','testDB');
    echo
'connect success';
} catch (
Exception $e) {
    echo
'ERROR:'.$e->getMessage();
}
fibrizo dot raziel at gmail dot com 02-Nov-2015 03:34
<?php  mysqli_report(MYSQLI_REPORT_STRICT) ?>
was not enough for me to enable exception throwing. I had to write this:
<?php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); ?>
callforeach at gmail dot com 10-Mar-2015 01:42
Please note that MYSQLI_REPORT_STRICT does not allow certain exceptions to be trapped. I find MYSQLI_REPORT_ALL to be more friendly since it allows me to trap all errors and handle them appropriately.
polyanin at gmail dot com 18-Feb-2014 06:51
$driver = new mysqli_driver();
        $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
PHP8中文手册 站长在线 整理 版权归PHP文档组所有