首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

mysqli_driver::$report_mode

(PHP 5, PHP 7)

mysqli_driver :: $ report_mode - mysqli_report - 启用或禁用内部报告功能

描述

面向对象的风格

int $mysqli_driver->report_mode ;

程序风格

代码语言:javascript
复制
bool mysqli_report ( int $flags )

一个函数有助于在代码开发和测试期间改进查询。根据标志,它会报告来自mysqli函数调用的错误或不使用索引的查询(或使用错误的索引)。

参数

flags

Name

Description

MYSQLI_REPORT_OFF

Turns reporting off

MYSQLI_REPORT_ERROR

Report errors from mysqli function calls

MYSQLI_REPORT_STRICT

Throw mysqli_sql_exception for errors instead of warnings

MYSQLI_REPORT_INDEX

Report if no index or bad index was used in a query

MYSQLI_REPORT_ALL

Set all options (report all)

返回值

TRUE成功或FALSE失败时返回。

更新日志

Version

Description

5.3.4

Changing the reporting mode is now be per-request, rather than per-process.

5.2.15

Changing the reporting mode is now be per-request, rather than per-process.

例子

Example#1 面向对象的风格

代码语言:javascript
复制
<?php

$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");

/*?check?connection?*/
if?(mysqli_connect_errno())?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}

/*?activate?reporting?*/
$driver?=?new?mysqli_driver();
$driver->report_mode?=?MYSQLI_REPORT_ALL;

try?{

????/*?this?query?should?report?an?error?*/
????$result?=?$mysqli->query("SELECT?Name?FROM?Nonexistingtable?WHERE?population?>?50000");

????/*?this?query?should?report?a?bad?index?*/
????$result?=?$mysqli->query("SELECT?Name?FROM?City?WHERE?population?>?50000");

????$result->close();

????$mysqli->close();

}?catch?(mysqli_sql_exception?$e)?{

????echo?$e->__toString();
}
?>

示例#2 程序风格

代码语言:javascript
复制
<?php
/*?activate?reporting?*/
mysqli_report(MYSQLI_REPORT_ALL);

$link?=?mysqli_connect("localhost",?"my_user",?"my_password",?"world");

/*?check?connection?*/
if?(mysqli_connect_errno())?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}

/*?this?query?should?report?an?error?*/
$result?=?mysqli_query("SELECT?Name?FROM?Nonexistingtable?WHERE?population?>?50000");

/*?this?query?should?report?a?bad?index?*/
$result?=?mysqli_query("SELECT?Name?FROM?City?WHERE?population?>?50000");

mysqli_free_result($result);

mysqli_close($link);
?>

也可以看看

  • mysqli_debug() - 执行调试操作
  • mysqli_dump_debug_info() - 将调试信息转储到日志中
  • mysqli_sql_exception
  • set_exception_handler() - 设置用户定义的异常处理函数
  • error_reporting() - 设置报告哪些 PHP 错误

← mysqli_driver::embedded_server_start

mysqli_warning →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com