gpt4 book ai didi

php - 当 mysql_query 返回 false 时

转载 作者:可可西里 更新时间:2023-11-01 06:27:57 26 4
gpt4 key购买 nike

除了编写错误的查询和没有访问表的权限外,当 mysql_query 返回 false 时?还有其他情况吗?

最佳答案

参见引用指南:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

http://php.net/manual/en/function.mysql-query.php

编辑:澄清这些错误实际上是什么。

所以我们有一个可以返回 false 的列表:

  • 当返回结果集的 MySQL 语句出错时
  • 当不返回任何内容的 MySQL 语句出错时
  • 当用户没有访问表引用的 MySQL 权限时

在我看来,前两个有点分散。可能的错误是什么?您可以从 MySQL 获得 59 种不同的客户端错误。这些是更多与系统相关的错误,我们可以假设 php 将处理这些错误并可能将其包装成更少量的抽象错误。

除了那些客户端错误之外,您还有一组更抽象的错误,这些错误在使用过程中可能会遇到,这些错误与在应用程序内部使用实际 API 而不是对 MySQL 服务器的原始访问更相关。它们是:

  • 访问被拒绝
  • 无法连接到[本地] MySQL 服务器
  • 失去与 MySQL 服务器的连接
  • 客户端不支持认证协议(protocol)
  • 交互式输入密码失败
  • 主机“host_name”被阻止
  • 连接太多
  • 内存不足
  • MySQL 服务器已经消失
  • 数据包太大
  • 通信错误和中止的连接
  • table 满了
  • 无法创建/写入文件
  • 命令不同步
  • 忽略用户
  • 表 'tbl_name' 不存在
  • 无法初始化字符集
  • 表损坏问题
  • 语法相关问题

下面是我刚才说的引用资料:

关于php - 当 mysql_query 返回 false 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8576902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com