gpt4 book ai didi

php - 当 mysql_query 返回 false 时

转载 作者:行者123 更新时间:2023-11-29 23:59:28 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/25146884/

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