mysql错误处理!

sunlijun 2007-04-05 01:21:01
我想显示mysql错误是位汉字,例如显示主键已存在,应该怎样做?
...全文
1418 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
oraclemch 2010-06-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 you_kind 的回复:]
存储过程里有异常处理,可以捕捉错误码然后自己写中文

麻烦而低效而没必要的做法。。。
[/Quote]

可以不可以自己事先写一个错误码跟中文对照的函数,然后再存储过程里面调用这个函数 获得出错中文信息呢?
helloyou0 2007-04-06
  • 打赏
  • 举报
回复
改 share/errmsg.txt 这个文件里的内容
you_kind 2007-04-06
  • 打赏
  • 举报
回复
存储过程里有异常处理,可以捕捉错误码然后自己写中文

麻烦而低效而没必要的做法。。。
爱着有你 2007-04-05
  • 打赏
  • 举报
回复
mysql_error()这个方法,使它在不同的错误代码时返回不同的中文提示
sunlijun 2007-04-05
  • 打赏
  • 举报
回复
重写什么文件?应注意什么?
爱着有你 2007-04-05
  • 打赏
  • 举报
回复
上面发的前者是MYSQL的错误信息代码,后面是PHP的函数。
可根据mysql_errno来输出不同的值,或者重写mysql_error也可以。

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('' . mysql_error());
爱着有你 2007-04-05
  • 打赏
  • 举报
回复
mysql_errno -- 返回上一个 MySQL 操作中的错误信息的数字编码
mysql_error -- 返回上一个 MySQL 操作产生的文本错误信息
爱着有你 2007-04-05
  • 打赏
  • 举报
回复
C.2. Client Error Codes and Messages
Client error information comes from the following source files:

The Error values and the symbols in parentheses correspond to definitions in the include/errmsg.h MySQL source file.

The Message values correspond to the error messages that are listed in the libmysql/errmsg.c file. %d and %s represent numbers and strings, respectively, that are substituted into the messages when they are displayed.

Because updates are frequent, it is possible that those files will contain additional error information not listed here.

Error: 2000 (CR_UNKNOWN_ERROR)

Message: Unknown MySQL error

Error: 2001 (CR_SOCKET_CREATE_ERROR)

Message: Can't create UNIX socket (%d)

Error: 2002 (CR_CONNECTION_ERROR)

Message: Can't connect to local MySQL server through socket '%s' (%d)

Error: 2003 (CR_CONN_HOST_ERROR)

Message: Can't connect to MySQL server on '%s' (%d)

Error: 2004 (CR_IPSOCK_ERROR)

Message: Can't create TCP/IP socket (%d)

Error: 2005 (CR_UNKNOWN_HOST)

Message: Unknown MySQL server host '%s' (%d)

Error: 2006 (CR_SERVER_GONE_ERROR)

Message: MySQL server has gone away

Error: 2007 (CR_VERSION_ERROR)

Message: Protocol mismatch; server version = %d, client version = %d

Error: 2008 (CR_OUT_OF_MEMORY)

Message: MySQL client ran out of memory

Error: 2009 (CR_WRONG_HOST_INFO)

Message: Wrong host info

Error: 2010 (CR_LOCALHOST_CONNECTION)

Message: Localhost via UNIX socket

Error: 2011 (CR_TCP_CONNECTION)

Message: %s via TCP/IP

Error: 2012 (CR_SERVER_HANDSHAKE_ERR)

Message: Error in server handshake

Error: 2013 (CR_SERVER_LOST)

Message: Lost connection to MySQL server during query

Error: 2014 (CR_COMMANDS_OUT_OF_SYNC)

Message: Commands out of sync; you can't run this command now

Error: 2015 (CR_NAMEDPIPE_CONNECTION)

Message: Named pipe: %s

Error: 2016 (CR_NAMEDPIPEWAIT_ERROR)

Message: Can't wait for named pipe to host: %s pipe: %s (%lu)

Error: 2017 (CR_NAMEDPIPEOPEN_ERROR)

Message: Can't open named pipe to host: %s pipe: %s (%lu)

Error: 2018 (CR_NAMEDPIPESETSTATE_ERROR)

Message: Can't set state of named pipe to host: %s pipe: %s (%lu)

Error: 2019 (CR_CANT_READ_CHARSET)

Message: Can't initialize character set %s (path: %s)

Error: 2020 (CR_NET_PACKET_TOO_LARGE)

Message: Got packet bigger than 'max_allowed_packet' bytes

Error: 2021 (CR_EMBEDDED_CONNECTION)

Message: Embedded server

Error: 2022 (CR_PROBE_SLAVE_STATUS)

Message: Error on SHOW SLAVE STATUS:

Error: 2023 (CR_PROBE_SLAVE_HOSTS)

Message: Error on SHOW SLAVE HOSTS:

Error: 2024 (CR_PROBE_SLAVE_CONNECT)

Message: Error connecting to slave:

Error: 2025 (CR_PROBE_MASTER_CONNECT)

Message: Error connecting to master:

Error: 2026 (CR_SSL_CONNECTION_ERROR)

Message: SSL connection error

Error: 2027 (CR_MALFORMED_PACKET)

Message: Malformed packet

Error: 2028 (CR_WRONG_LICENSE)

Message: This client library is licensed only for use with MySQL servers having '%s' license

Error: 2029 (CR_NULL_POINTER)

Message: Invalid use of null pointer

Error: 2030 (CR_NO_PREPARE_STMT)

Message: Statement not prepared

Error: 2031 (CR_PARAMS_NOT_BOUND)

Message: No data supplied for parameters in prepared statement

Error: 2032 (CR_DATA_TRUNCATED)

Message: Data truncated

Error: 2033 (CR_NO_PARAMETERS_EXISTS)

Message: No parameters exist in the statement

Error: 2034 (CR_INVALID_PARAMETER_NO)

Message: Invalid parameter number

Error: 2035 (CR_INVALID_BUFFER_USE)

Message: Can't send long data for non-string/non-binary data types (parameter: %d)

Error: 2036 (CR_UNSUPPORTED_PARAM_TYPE)

Message: Using unsupported buffer type: %d (parameter: %d)

Error: 2037 (CR_SHARED_MEMORY_CONNECTION)

Message: Shared memory: %s

Error: 2038 (CR_SHARED_MEMORY_CONNECT_REQUEST_ERROR)

Message: Can't open shared memory; client could not create request event (%lu)

Error: 2039 (CR_SHARED_MEMORY_CONNECT_ANSWER_ERROR)

Message: Can't open shared memory; no answer event received from server (%lu)

Error: 2040 (CR_SHARED_MEMORY_CONNECT_FILE_MAP_ERROR)

Message: Can't open shared memory; server could not allocate file mapping (%lu)

Error: 2041 (CR_SHARED_MEMORY_CONNECT_MAP_ERROR)

Message: Can't open shared memory; server could not get pointer to file mapping (%lu)

Error: 2042 (CR_SHARED_MEMORY_FILE_MAP_ERROR)

Message: Can't open shared memory; client could not allocate file mapping (%lu)

Error: 2043 (CR_SHARED_MEMORY_MAP_ERROR)

Message: Can't open shared memory; client could not get pointer to file mapping (%lu)

Error: 2044 (CR_SHARED_MEMORY_EVENT_ERROR)

Message: Can't open shared memory; client could not create %s event (%lu)

Error: 2045 (CR_SHARED_MEMORY_CONNECT_ABANDONED_ERROR)

Message: Can't open shared memory; no answer from server (%lu)

Error: 2046 (CR_SHARED_MEMORY_CONNECT_SET_ERROR)

Message: Can't open shared memory; cannot send request event to server (%lu)

Error: 2047 (CR_CONN_UNKNOW_PROTOCOL)

Message: Wrong or unknown protocol

Error: 2048 (CR_INVALID_CONN_HANDLE)

Message: Invalid connection handle

Error: 2049 (CR_SECURE_AUTH)

Message: Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)

Error: 2050 (CR_FETCH_CANCELED)

Message: Row retrieval was canceled by mysql_stmt_close() call

Error: 2051 (CR_NO_DATA)

Message: Attempt to read column without prior row fetch

Error: 2052 (CR_NO_STMT_METADATA)

Message: Prepared statement contains no metadata

Error: 2053 (CR_NO_RESULT_SET)

Message: Attempt to read a row while there is no result set associated with the statement

Error: 2054 (CR_NOT_IMPLEMENTED)

Message: This feature is not implemented yet

Error: 2055 (CR_SERVER_LOST_EXTENDED)

Message: Lost connection to MySQL server at '%s', system error: %d

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧