How do you check sql query is correct or not in php?
From MySQL 5.6.3 on you can use EXPLAIN for most queries Show I made this and it works lovely:
It wil return False if de query is OK (multiple ; separated statements allowed), or an error message stating the error if there is a syntax or other MySQL other (like non-existent table or column). PHP Fiddle KNOWN BUGS:
(PHP 4, PHP 5) mysql_query — Send a MySQL query Descriptionmysql_query(string Parametersquery 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 the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an
Return Values For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns
The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data. Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement. mysql_query() will also fail and return ExamplesExample #1 Invalid Query The following query is syntactically invalid, so mysql_query() fails and returns
Example #2 Valid Query The following query is valid, so mysql_query() returns a resource.
See Also
jack dot whoami at gmail dot com ¶ 15 years ago
halion at gmail dot com ¶ 15 years ago
nikhil-php at nols dot com ¶ 22 years ago
Anonymous ¶ 16 years ago
mysql_query($query); Mr. Tim ¶ 14 years ago
davidc at edeca dot net ¶ 19 years ago
ialsoagree ¶ 13 years ago
ddlshack [at] gmail.dot.com ¶ 11 years ago
mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')'); masteracc0 at aol dot com ¶ 14 years ago
rob desbois ¶ 16 years ago
veyita_angi at hotmail dot com ¶ 15 years ago
php at arcannon dot com ¶ 16 years ago
Anonymous ¶ 19 years ago
rogier ¶ 14 years ago
cc+php at c2se dot com ¶ 16 years ago
mysql_query_params__callback( $at ) { ix at nivelzero dot ro ¶ 17 years ago
fernandoleal at loytek dot com ¶ 14 years ago
mwwaygoo at hotmail dot com ¶ 10 years ago
jon at websandbox dot net ¶ 17 years ago
Anonymous ¶ 13 years ago
Predrag Supurovic ¶ 18 years ago
allen a brooker gb net ¶ 19 years ago
Richie (at) RichieBartlett.com ¶ 13 years ago
= mysql_connect('YOUR_DB_ADDRESS','YOUR_DB_USER','YOUR_DB_PASS') or die("Database error");
chris at hotmail dot com ¶ 19 years ago
wjyong at sh263 dot net ¶ 17 years ago
How do I check if SQL query is correct in PHP?Linked. check if the query results empty row mysqli.. Run a PHP function if returned SQL data matches a specific value.. How to Display a message when no results found in PHP MySQL search.. Check whether mysql query returned an empty resultset.. Query result is true instead of false.. How do you check SQL query is correct or not?To check syntax code:
First, Drag and drop your SQL file or copy / paste your request directly into the editor above. Finally, you must click on "Check SQL syntax" button to display if there is an syntax error in your code.
How do I check if SQL query returns nothing PHP?How do I check if SQL query returns nothing PHP? The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.
How SQL queries are run in PHP?Parameter Values. |