★ wanayoo — archive 1999 http://www.php.net/manual/function.mysql-error.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to MySQL
Quick Reference
MySQL
* mysql_affected_rows
* mysql_change_user
* mysql_close
* mysql_connect
* mysql_create_db
* mysql_data_seek
* mysql_db_query
* mysql_drop_db
* mysql_errno
* mysql_error
* mysql_fetch_array
* mysql_fetch_field
* mysql_fetch_lengths
* mysql_fetch_object
* mysql_fetch_row
* mysql_field_name
* mysql_field_seek
* mysql_field_table
* mysql_field_type
* mysql_field_flags
* mysql_field_len
* mysql_free_result
* mysql_insert_id
* mysql_list_fields
* mysql_list_dbs
* mysql_list_tables
* mysql_num_fields
* mysql_num_rows
* mysql_pconnect
* mysql_query
* mysql_result
* mysql_select_db
* mysql_tablename
Manual: mysql_error
View the source code for this pageSearch the site



Previous page
 mysql_errno
mysql_fetch_array 
Next page


mysql_error

(PHP3 , PHP4 )

mysql_error -- Returns the text of the error message from previous MySQL operation

Description

string mysql_error ([int link_identifier])

Errors coming back from the mySQL database backend no longer issue warnings. Instead, use these functions to retrieve the error string.

  1 
  2 <?php
  3 mysql_connect("marliesle");
  4 echo mysql_errno().": ".mysql_error()."<BR>";
  5 mysql_select_db("nonexistentdb");
  6 echo mysql_errno().": ".mysql_error()."<BR>";
  7 $conn = mysql_query("SELECT * FROM nonexistenttable");
  8 echo mysql_errno().": ".mysql_error()."<BR>";
  9 ?>
 10       

See also: mysql_errno()


User Contributed Notes: mysql_error


dstocks@foothill.net
07-May-2000 12:08
Why is it that when I run the above example the first call to mysql_errno() and mysql_error() both return nothing but the second calls return the proper error numbers and messages? I am trying to trap connection errors and these two always return empty after the connect fails. Other mysql error statements trap fine. Here is what I get when I run the above script. Warning: MySQL Connection Failed: Unknown MySQL Server Host 'marliesle' (0) in /home/httpd/html//php/scripts/test2.php3 on line 2 : 1049: Unknown database 'nonexistentdb' 1046: No Database Selected See how the second two calls to mysql_errno and mysql_error work fine but the first line only echos the colon (:)? I don't get it. I even messed with the error_reporting level to suppress the error message and the first line still comes back empty. Any help would be greatly appreciated! Thanks, Don


ehillman@REMOVETHISWORD.cccu.com
10-May-2000 05:10
This is a weird bit of errata -- in PHP3, mysql_error() and mysql_errno() can't report errors on mysql_connect, only operations on a valid connection. Use something like: mysql_connect("somedb") or die("Couldn't connect to somedb: $php_errormsg"); instead.


 About Notes


Previous page
 mysql_errno
mysql_fetch_array 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.