Mysql Error Check
Contents |
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache mysql error php module Session Security Filesystem Security Database Security Error Reporting Using Register Globals User php mysqli error Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file
Mysql Query Error
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
Php Mysql Error Handling
Extensions Compression and Archive Extensions Credit Card 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 or die mysql error 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 from previous MySQL operation Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_error() PDO::errorInfo() Description string mysql_error ([ resource $link_identifier = NULL ] ) Returns the error text from the last MySQL function. Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_error() to retrieve the error text. Note that this function only returns th
Connectors More MySQL.com Downloads Developer Zone Section Menu: Documentation Home MySQL 5.7 Reference Manual Preface and Legal Notices General Information Installing and
Mysql_query Error
Upgrading MySQL Using MySQL as a Document Store Tutorial MySQL mysqli_query error Programs MySQL Server Administration Security Backup and Recovery Optimization Language Structure Globalization Data Types Functions and die(mysql_error()) Operators SQL Statement Syntax Data Definition Statements ALTER DATABASE Syntax ALTER EVENT Syntax ALTER FUNCTION Syntax ALTER INSTANCE Syntax ALTER LOGFILE GROUP Syntax ALTER PROCEDURE Syntax ALTER http://php.net/manual/en/function.mysql-error.php SERVER Syntax ALTER TABLE Syntax ALTER TABLE Partition Operations ALTER TABLE Online Operations in MySQL Cluster ALTER TABLE and Generated Columns ALTER TABLE Examples ALTER TABLESPACE Syntax ALTER VIEW Syntax CREATE DATABASE Syntax CREATE EVENT Syntax CREATE FUNCTION Syntax CREATE INDEX Syntax CREATE LOGFILE GROUP Syntax CREATE PROCEDURE and CREATE FUNCTION Syntax CREATE http://dev.mysql.com/doc/mysql/en/check-table.html SERVER Syntax CREATE TABLE Syntax CREATE TABLE ... LIKE Syntax CREATE TABLE ... SELECT Syntax Using FOREIGN KEY Constraints Silent Column Specification Changes CREATE TABLE and Generated Columns Secondary Indexes and Generated Virtual Columns Setting NDB_TABLE options in table comments CREATE TABLESPACE Syntax CREATE TRIGGER Syntax CREATE VIEW Syntax DROP DATABASE Syntax DROP EVENT Syntax DROP FUNCTION Syntax DROP INDEX Syntax DROP LOGFILE GROUP Syntax DROP PROCEDURE and DROP FUNCTION Syntax DROP SERVER Syntax DROP TABLE Syntax DROP TABLESPACE Syntax DROP TRIGGER Syntax DROP VIEW Syntax RENAME TABLE Syntax TRUNCATE TABLE Syntax Data Manipulation Statements CALL Syntax DELETE Syntax DO Syntax HANDLER Syntax INSERT Syntax INSERT ... SELECT Syntax INSERT DELAYED Syntax INSERT ... ON DUPLICATE KEY UPDATE Syntax LOAD DATA INFILE Syntax LOAD XML Syntax REPLACE Syntax SELECT Syntax SELECT ... INTO Syntax JOIN Syntax UNION Syntax Subquery Syntax The Subquery as Scalar Operand Comparisons Using Subqueries Subqueries with ANY, IN, or SOME Subqueries with AL
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 about Stack Overflow the company Business Learn http://stackoverflow.com/questions/11918797/how-to-check-if-a-mysql-query-using-the-legacy-api-was-successful more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to check if a MySQL query using the legacy API was successful? up vote 30 down vote favorite 5 How do I check if a mysql error MySQL query is successful other than using die() I'm trying to achieve... mysql_query($query); if(success){ //move file } else if(fail){ //display error } php mysql share|improve this question edited Jun 13 at 8:52 Álvaro González 81.1k20133201 asked Aug 12 '12 at 0:27 JohnSmith 3892921 add a comment| 6 Answers 6 active oldest votes up vote 50 down vote accepted This is the first example in the manual page for mysql_query: $result = mysql_query('SELECT * WHERE 1=1'); if mysql error check (!$result) { die('Invalid query: ' . mysql_error()); } If you wish to use something other than die, then I'd suggest trigger_error. share|improve this answer edited Aug 12 '12 at 1:01 answered Aug 12 '12 at 0:29 Mark Byers 449k8810941194 3 Or simply if (!mysql_query('SELECT * WHERE 1=1')) { ... } –Rune Aug 12 '12 at 0:32 1 @Rune: Right, but then you won't be able to use the query resource for further actions (i.e. for fetching actual data using mysql_fetch_* functions). –Amal Murali May 21 '14 at 13:36 @AmalMurali hmm, good point. I'm not sure where I was with my head at the time of posting that comment.. –Rune May 22 '14 at 19:44 1 Use $result === false not !$result. REASON: There may be queries for which $result is a VALID (non-error) value that is equivalent to ZERO. (I think an empty string is another example.) In php, !0 evaluates to true, so your die would execute, even though is not an error. SIMILARLY, when you want the opposite test, for code that should execute when there is not an error, use if ($result !== false) rather than if ($result). –ToolmakerSteve May 13 at 18:50 add a comment| up vote 11 down vote You can use mysql_errno() for this too. $result = mysql_query($query); if(mysql_errno()){ echo "MySQL error ".mysql_errno().": " .mysql_error()."\n<