mysql_db_query() Function in PHP

What is mysql_db_query() function in PHP?
How does mysql_db_query() works?

Explanation

The mysql_db_query() function queries a MySQL database .
Syntax
resource mysql_db_query ( string database, string query [, resource link_identifier])

Returns a positive MySQL result resource to the query result, or FALSE on error.
mysql_db_query() selects a database and executes a query on it using the MySQL server connection referenced by connection. Unlike, mysql_query, this function allows you to specify a database to use (in the event that more than one database is available to the user on the connection.). If no connection is specified in the connection argument, the last opened connection will be used by default. If no connection is open, mysql_db_query() attempts to connect to a MySQL database by calling mysql_connect() without arguments.
The value returned depends on the query made. SELECT, DESCRIBE and SHOW queries return a MySQL result handle if successful or FALSE on failure.
Example

<?php
// Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
$sql = 'SELECT * FROM tblState';
// run a 'select' on the 'system' database
$data = mysql_db_query('system', $sql, $link);
mysql_close($link) ;
?>

See also: mysql_connect() and mysql_query()

PHP Topics


Ask Questions

Ask Question