Error Handling Mysql_query
Contents |
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 module Session Security Filesystem Security Database Security php mysql query error handling Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping mysqli query error handling Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent error handling in mysql stored procedure 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
Mysql_query Php
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 mysql_query insert 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_real_escape_string » « mysql_ping 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_query (PHP 4, PHP 5)mysql_query — Send a MySQL query 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_query() PDO::query() Description mixed mysql_query ( string $query [, resource $link_identifier = NULL ] ) mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier. Parameters query An SQL query The query string should not end with a semicolon. Data inside the query should be properly escaped. link_identifier The MySQL connection. If t
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 mysqli query php About Us Learn more about Stack Overflow the company Business Learn more about
Mysql Query Where
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join
Mysql_query Deprecated
the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up if mysql_query() fails, what to http://php.net/manual/en/function.mysql-query.php do? up vote 8 down vote favorite Sometimes so happens that mysql_query() fails to INSERT data and I am unaware of it. So, the question is how do I know when it happens? php mysql security share|improve this question edited Apr 10 '10 at 4:10 Mark Rushakoff 137k22294346 asked Mar 10 '10 at 4:42 Wohell 46112 3 I don't think this question deserves downvotes. http://stackoverflow.com/questions/2414569/if-mysql-query-fails-what-to-do It's basic, but it's reasonably well-phrased and the answers so far have been sincere. You jerkfaces from Pod Six need to cut it out. –Andrew Heath Mar 10 '10 at 5:55 add a comment| 9 Answers 9 active oldest votes up vote 6 down vote Quoting the documentation page of mysql_query : For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. So, to detect whether there's been an error or not, you have to test the return value of your call to mysql_query : $result = mysql_query('...'); if ($result === false) { // And error has occured while executing // the SQL query } Then, what can you do ? Well, first, you can log the error to a file, that you can analyse later For than, you can use mysql_error and mysql_errno. And you can display a nice error message the user i.e. some kind of "oops, an error occured page". Remember, though : the user doesn't need to know (and will
remains empty. I have found many proposed solutions for similar situations (including in this forum), but none of them have helped. For https://www.sitepoint.com/community/t/mysql-query-insert-into-fails-but-no-error-is-returned/33254 example, using back ticks instead of single quotes around the values, INSERT might be sending empty values, values might not be reaching the function - along with a few other suggested fixes which didn't work. Unfortunately, I don't have direct access to the db. So, I'm taking the clients word that the table is empty, she seems to know what she's doing, I error handling don't have any reason to doubt what she says. Can anyone throw some new light on this for me - thanks function store_details($db_server, $db_user, $db_pass, $db_name, $ftp_server, $subject, $skipfile, $skipdir, $rename_file, $alert, $from, $message, $createLog, $cronlogpath){ $date = date ("dMy"); $time = date("H:i"); $site_table = 'ssa_'.str_replace('-','$',str_replace('.','_',$ftp_server)).'_site'; $con = mysql_connect($db_server,$db_user,$db_pass)or die('Unable to connect to MySQL server: '.$db_server.'
Please check that the following details are correct:
query error handling db server name
db user name
db password
Click to reload form'); mysql_select_db($db_name, $con)or die('Connected but, unable to select db! '.mysql_error()); $query = "TRUNCATE TABLE $site_table"; mysql_query($query)or die('Failed to empty site table
'.mysql_error()); $query ="INSERT INTO $site_table ( email_subj, email_alert, skip_files, skip_dir, from_addr, email_header, cron_path, rename_file, SSA_log, date, time ) VALUES ( '$subject', '$alert', '$skipfile', '$skipdir', '$from', '$message', '$cronlogpath', '$rename_file', '$createLog', '$date', '$time')"; mysql_query($query) or die('Failed to update site table. Mysql returned the following:
'.mysql_error()); mysql_close($con)or die(mysql_error()); } ginerjm 2013-07-28 13:26:22 UTC #2 Do you have error checking enabled to see if you just have some simple php error not related to the db actions? 2ndmouse 2013-07-28 21:14:45 UTC #3 Hi ginerjm I had error checking enabled. Still nothing in the db and no error revealed. I'm about to try a different approach by calling a separate function to do a bit of sanitisation and then do the query. The new function is below. $inserts //is an array where the keys are the column names and the values are the values to be inserted $table //is the name of the table function mysql_insert($table, $inserts) { $values = array_map('mysql_r