PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_db_query() Function in PHP


Tutorials »Php »

Topic

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()





Other Links

web hosting