PHP Function Mysql_Query
The php function mysql_query is used to execute SQL query in MySQL. This function returns the query handle for SELECT queries and TRUE/FALSE on failure.
The mysql_query() function requires a valid database connection and an array of parameters. The parameter array should match the data type of the query field. If you try to run a SELECT query with an unmatched parameter array or if one of the parameters is not a string value, the MySQL server will return an error message.
Aside from a SELECT query mysql_query() also supports other operations like INSERT, UPDATE and DELETE statements. These are done through a result table. The result table is returned as an associative array and you can access individual rows using their names.
Suppose you want to fetch all records from the employee table. This can be done by using the mysql_fetch_array() function and you can specify a key as an index. Alternatively you can use the constant MYSQL_ASSOC to return the row as an associative array or MYSQL_NUM to return it as a numeric array.
If you are using a version of PHP that doesn't support the mysql extension, you should use the PDO library instead. This will provide you with a non-persistent connection to the database and many of the mysql_query() functions have an equivalent in PDO. You should also migrate your code to mysqli, which is the procedural method that replaces the MySQL Connect function. This article will show you some simple ways to move your code from mysql_query to mysqli.