Name

mysql_db_query( )

Synopsis

mysql_db_query(database, sql_statement[, connection])

Use this to query the database given, for the current MySQL connection (unless another is specified), and to execute the SQL statement given as the second argument. If there isn’t currently a connection to the server, it will attempt to establish one. For SQL statements that would not return a results set (e.g., UPDATE statements), true will be returned if the function is successful and false if it’s unsuccessful. The mysql_query( ) function may be used instead if the statement is to be executed on the current database.

...
$sql_stmnt = "SELECT wrid, clientid, description
              FROM workreq";
$results = mysql_db_query('workrequests', $sql_stmnt);
while($row = mysql_fetch_object($results)) {
  print "WR-" . $row->wrid . ",
         Client-" . $row->clientid . " " .
         $row->description . "\n";
}
...

Basically, using mysql_db_query( ) eliminates the need to use mysql_select_db( ) and mysql_query( ).

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.