PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




mysql_errno

Name

mysql_errno — Gets the error code from the last MySQL operation

Synopsis

int mysql_errno([connection]);
mysql link connection (optional): Connection handle returned by mysql_connect() or mysql_pconnect()

Returns

Integer on success; FALSE on error

Description

mysql_errno() returns the MySQL error code from the last MySQL function call that invoked a MySQL client routine. If no error occurred, 0 is returned. In many cases, developers will find the mysql_error() function more useful than mysql_errno() , as it returns a human-readable error message. The error codes are quite useful when dealing with sites that support multiple languages, allowing developers to more easily deliver error messages in multiple languages.

There are more than 200 error codes. MySQL provides a series of convenience constants for these codes. You can get a current version by viewing the include/errmsg.h and include/mysqld_error.h files in the MySQL source code distribution (available from http://www.mysql.com).

Error Code Constant Name
198 ER_ERROR_MESSAGES
1000 ER_HASHCHK
1001 ER_NISAMCHK
1002 ER_NO
1003 ER_YES
1004 ER_CANT_CREATE_FILE
1005 ER_CANT_CREATE_TABLE
1006 ER_CANT_CREATE_DB
1007 ER_DB_CREATE_EXISTS
1008 ER_DB_DROP_EXISTS
1009 ER_DB_DROP_DELETE
1010 ER_DB_DROP_RMDIR
1011 ER_CANT_DELETE_FILE
1012 ER_CANT_FIND_SYSTEM_REC
1013 ER_CANT_GET_STAT
1014 ER_CANT_GET_WD
1015 ER_CANT_LOCK
1016 ER_CANT_OPEN_FILE
1017 ER_FILE_NOT_FOUND
1018 ER_CANT_READ_DIR
1019 ER_CANT_SET_WD
1020 ER_CHECKREAD
1021 ER_DISK_FULL
1022 ER_DUP_KEY
1023 ER_ERROR_ON_CLOSE
1024 ER_ERROR_ON_READ
1025 ER_ERROR_ON_RENAME
1026 ER_ERROR_ON_WRITE
1027 ER_FILE_USED
1028 ER_FILSORT_ABORT
1029 ER_FORM_NOT_FOUND
1030 ER_GET_ERRNO
1031 ER_ILLEGAL_HA
1032 ER_KEY_NOT_FOUND
1033 ER_NOT_FORM_FILE
1034 ER_NOT_KEYFILE
1035 ER_OLD_KEYFILE
1036 ER_OPEN_AS_READONLY
1037 ER_OUTOFMEMORY
1038 ER_OUT_OF_SORTMEMORY
1039 ER_UNEXPECTED_EOF
1040 ER_CON_COUNT_ERROR
1041 ER_OUT_OF_RESOURCES
1042 ER_BAD_HOST_ERROR
1043 ER_HANDSHAKE_ERROR
1044 ER_DBACCESS_DENIED_ERROR
1045 ER_ACCESS_DENIED_ERROR
1046 ER_NO_DB_ERROR
1047 ER_UNKNOWN_COM_ERROR
1048 ER_BAD_NULL_ERROR
1049 ER_BAD_DB_ERROR
1050 ER_TABLE_EXISTS_ERROR
1051 ER_BAD_TABLE_ERROR
1052 ER_NON_UNIQ_ERROR
1053 ER_SERVER_SHUTDOWN
1054 ER_BAD_FIELD_ERROR
1055 ER_WRONG_FIELD_WITH_GROUP
1056 ER_WRONG_GROUP_FIELD
1057 ER_WRONG_SUM_SELECT
1058 ER_WRONG_VALUE_COUNT
1059 ER_TOO_LONG_IDENT
1060 ER_DUP_FIELDNAME
1061 ER_DUP_KEYNAME
1062 ER_DUP_ENTRY
1063 ER_WRONG_FIELD_SPEC
1064 ER_PARSE_ERROR
1065 ER_EMPTY_QUERY
1066 ER_NONUNIQ_TABLE
1067 ER_INVALID_DEFAULT
1068 ER_MULTIPLE_PRI_KEY
1069 ER_TOO_MANY_KEYS
1070 ER_TOO_MANY_KEY_PARTS
1071 ER_TOO_LONG_KEY
1072 ER_KEY_COLUMN_DOES_NOT_EXITS
1073 ER_BLOB_USED_AS_KEY
1074 ER_TOO_BIG_FIELDLENGTH
1075 ER_WRONG_AUTO_KEY
1076 ER_READY
1077 ER_NORMAL_SHUTDOWN
1078 ER_GOT_SIGNAL
1079 ER_SHUTDOWN_COMPLETE
1080 ER_FORCING_CLOSE
1081 ER_IPSOCK_ERROR
1082 ER_NO_SUCH_INDEX
1083 ER_WRONG_FIELD_TERMINATORS
1084 ER_BLOBS_AND_NO_TERMINATED
1085 ER_TEXTFILE_NOT_READABLE
1086 ER_FILE_EXISTS_ERROR
1087 ER_LOAD_INFO
1088 ER_ALTER_INFO
1089 ER_WRONG_SUB_KEY
1090 ER_CANT_REMOVE_ALL_FIELDS
1091 ER_CANT_DROP_FIELD_OR_KEY
1092 ER_INSERT_INFO
1093 ER_INSERT_TABLE_USED
1094 ER_NO_SUCH_THREAD
1095 ER_KILL_DENIED_ERROR
1096 ER_NO_TABLES_USED
1097 ER_TOO_BIG_SET
1098 ER_NO_UNIQUE_LOGFILE
1099 ER_TABLE_NOT_LOCKED_FOR_WRITE
1100 ER_TABLE_NOT_LOCKED
1101 ER_BLOB_CANT_HAVE_DEFAULT
1102 ER_WRONG_DB_NAME
1103 ER_WRONG_TABLE_NAME
1104 ER_TOO_BIG_SELECT
1105 ER_UNKNOWN_ERROR
1106 ER_UNKNOWN_PROCEDURE
1107 ER_WRONG_PARAMCOUNT_TO_PROCEDURE
1108 ER_WRONG_PARAMETERS_TO_PROCEDURE
1109 ER_UNKNOWN_TABLE
1110 ER_FIELD_SPECIFIED_TWICE
1111 ER_INVALID_GROUP_FUNC_USE
1112 ER_UNSUPPORTED_EXTENSION
1113 ER_TABLE_MUST_HAVE_COLUMNS
1114 ER_RECORD_FILE_FULL
1115 ER_UNKNOWN_CHARACTER_SET
1116 ER_TOO_MANY_TABLES
1117 ER_TOO_MANY_FIELDS
1118 ER_TOO_BIG_ROWSIZE
1119 ER_STACK_OVERRUN
1120 ER_WRONG_OUTER_JOIN
1121 ER_NULL_COLUMN_IN_INDEX
1122 ER_CANT_FIND_UDF
1123 ER_CANT_INITIALIZE_UDF
1124 ER_UDF_NO_PATHS
1125 ER_UDF_EXISTS
1126 ER_CANT_OPEN_LIBRARY
1127 ER_CANT_FIND_DL_ENTRY
1128 ER_FUNCTION_NOT_DEFINED
1129 ER_HOST_IS_BLOCKED
1130 ER_HOST_NOT_PRIVILEGED
1131 ER_PASSWORD_ANONYMOUS_USER
1132 ER_PASSWORD_NOT_ALLOWED
1133 ER_PASSWORD_NO_MATCH
1134 ER_UPDATE_INFO
1135 ER_CANT_CREATE_THREAD
1136 ER_WRONG_VALUE_COUNT_ON_ROW
1137 ER_CANT_REOPEN_TABLE
1138 ER_INVALID_USE_OF_NULL
1139 ER_REGEXP_ERROR
1140 ER_MIX_OF_GROUP_FUNC_AND_FIELDS
1141 ER_NONEXISTING_GRANT
1142 ER_TABLEACCESS_DENIED_ERROR
1143 ER_COLUMNACCESS_DENIED_ERROR
1144 ER_ILLEGAL_GRANT_FOR_TABLE
1145 ER_GRANT_WRONG_HOST_OR_USER
1146 ER_NO_SUCH_TABLE
1147 ER_NONEXISTING_TABLE_GRANT
1148 ER_NOT_ALLOWED_COMMAND
1149 ER_SYNTAX_ERROR
1150 ER_DELAYED_CANT_CHANGE_LOCK
1151 ER_TOO_MANY_DELAYED_THREADS
1152 ER_ABORTING_CONNECTION
1153 ER_NET_PACKET_TOO_LARGE
1154 ER_NET_READ_ERROR_FROM_PIPE
1155 ER_NET_FCNTL_ERROR
1156 ER_NET_PACKETS_OUT_OF_ORDER
1157 ER_NET_UNCOMPRESS_ERROR
1158 ER_NET_READ_ERROR
1159 ER_NET_READ_INTERRUPTED
1160 ER_NET_ERROR_ON_WRITE
1161 ER_NET_WRITE_INTERRUPTED
1162 ER_TOO_LONG_STRING
1163 ER_TABLE_CANT_HANDLE_BLOB
1164 ER_TABLE_CANT_HANDLE_AUTO_INCREMENT
1165 ER_DELAYED_INSERT_TABLE_LOCKED
1166 ER_WRONG_COLUMN_NAME
1167 ER_WRONG_KEY_COLUMN
1168 ER_WRONG_MRG_TABLE
1169 ER_DUP_UNIQUE
1170 ER_BLOB_KEY_WITHOUT_LENGTH
1171 ER_PRIMARY_CANT_HAVE_NULL
1172 ER_TOO_MANY_ROWS
1173 ER_REQUIRES_PRIMARY_KEY
1174 ER_NO_RAID_COMPILED
1175 ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
1176 ER_KEY_DOES_NOT_EXITS
1177 ER_CHECK_NO_SUCH_TABLE
1178 ER_CHECK_NOT_IMPLEMENTED
1179 ER_CANT_DO_THIS_DURING_AN_TRANSACTION
1180 ER_ERROR_DURING_COMMIT
1181 ER_ERROR_DURING_ROLLBACK
1182 ER_ERROR_DURING_FLUSH_LOGS
1183 ER_ERROR_DURING_CHECKPOINT
1184 ER_NEW_ABORTING_CONNECTION
1185 ER_DUMP_NOT_IMPLEMENTED
1186 ER_FLUSH_MASTER_BINLOG_CLOSED
1187 ER_INDEX_REBUILD
1188 ER_MASTER
1189 ER_MASTER_NET_READ
1190 ER_MASTER_NET_WRITE
1191 ER_FT_MATCHING_KEY_NOT_FOUND
1192 ER_LOCK_OR_ACTIVE_TRANSACTION
1193 ER_UNKNOWN_SYSTEM_VARIABLE
1194 ER_CRASHED_ON_USAGE
1195 ER_CRASHED_ON_REPAIR
1196 ER_WARNING_NOT_COMPLETE_ROLLBACK
1197 ER_TRANS_CACHE_FULL
2000 CR_UNKNOWN_ERROR
2001 CR_SOCKET_CREATE_ERROR
2002 CR_CONNECTION_ERROR
2003 CR_CONN_HOST_ERROR
2004 CR_IPSOCK_ERROR
2005 CR_UNKNOWN_HOST
2006 CR_SERVER_GONE_ERROR
2007 CR_VERSION_ERROR
2008 CR_OUT_OF_MEMORY
2009 CR_WRONG_HOST_INFO
2010 CR_LOCALHOST_CONNECTION
2011 CR_TCP_CONNECTION
2012 CR_SERVER_HANDSHAKE_ERR
2013 CR_SERVER_LOST
2014 CR_COMMANDS_OUT_OF_SYNC
2015 CR_NAMEDPIPE_CONNECTION
2016 CR_NAMEDPIPEWAIT_ERROR
2017 CR_NAMEDPIPEOPEN_ERROR
2018 CR_NAMEDPIPESETSTATE_ERROR
2019 CR_CANT_READ_CHARSET
2020 CR_NET_PACKET_TOO_LARGE


Version

PHP 3+, PHP 4+

See also

To get a human-readable error message from the last MySQL query:

mysql_error()



Example

Example 798. Use the error codes returned by mysql_errno() for error log entries

<?php
// Connect to the default MySQL server
// Suppress any error messages with a single at (@) symbol
$mysql_link = @ mysql_connect ();

// If the connection failed, log the error to an error file
if ($mysql_link === FALSE) {
    // Write a terse message to an error log
    error_log (time() . '|' . mysql_errno () . "\n", 3, "mysql_err.log");

    // Redirect the client to a new page to handle the error
    header ("http://www.example.com/error.php?mysql%20connection%20error");
}

// If we made it past here, then we managed to connect
// Continue with the script as normal

echo "Connected to default MySQL server.";
?>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.