Php Catch Mysql Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Php Mysql Error Handling
about Stack Overflow the company Business Learn more about hiring developers or posting ads php mysqli error with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Mysql Error Php
is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Is there any way to catch MySQL and database errors in PHP? up php mysql exception handling vote 7 down vote favorite 2 Sometimes I am getting a database error like Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'101.190.193.83' (using password: YES) Could not connect: Access denied for user 'test'@'101.190.193.83' (using password: YES)" But truly there is no change in the password. Is there any way to capture this error in a log file and show some nice message on the screen, like "Server error. Please mysqli_query error try again some time." php mysql error-handling mysql-error-1045 share|improve this question edited Jun 4 '11 at 7:24 Peter Mortensen 10.3k1369107 asked May 25 '11 at 6:49 ASD 1,45692647 I'm actually working on an Open Source project to catch errors, show a nice message on the screen and log them with much more information than the standard error log provides. jarofgreen.co.uk/2011/01/tracking-errors-with-php or elastik.sf.net –James Jun 4 '11 at 7:31 add a comment| 5 Answers 5 active oldest votes up vote 8 down vote If you don't want PHP to show the warning, you have to use the "@" operator $connect = @mysql_connect(HOST, USER, PASS);//won't display the warning if any. if (!$connect) { echo 'Server error. Please try again sometime. CON'; } You may also consider setting display_errors to 0 in your php.ini file in production You may also consider PDO for connecting to MySQL, it's using exceptions as a default to report errors, try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Could not connect : ' . $e->getMessage(); } share|improve this answer edited Jun 4 '11 at 7:57 Peter Mortensen 10.3k1369107 answered May 25 '11 at 8:05 Gérald Croës 2,46011018 2 +1 using of PDO is highly recommended. –Ibrahi
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported
Or Die Mysql Error
Protocols and Wrappers Security Introduction General considerations Installed as i cannot select mysql database CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting
Mysql_errno
Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads http://stackoverflow.com/questions/6120589/is-there-any-way-to-catch-mysql-and-database-errors-in-php Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System http://php.net/manual/en/function.mysql-error.php Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box mysql_escape_string » « mysql_errno PHP Manual Function Reference Database Extensions Vendor Specific Database Extensions MySQL MySQL (Original) MySQL Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug mysql_error (PHP 4, PHP 5)mysql_error — Returns the text of the error message fro
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context http://php.net/manual/en/function.mysql-errno.php options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP mysql error Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card php catch mysql Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box mysql_error » « mysql_drop_db PHP Manual Function Reference Database Extensions Vendor Specific Database Extensions MySQL MySQL (Original) MySQL Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japane