Original MySQL API (
Mysql
)
2254
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
was called
with no arguments. If no connection is found or established, an
E_WARNING
level error is generated.
Return Values
Returns a positive MySQL result resource to the query result, or
FALSE
on error. The function also
returns
TRUE
/
FALSE
for
INSERT
/
UPDATE
/
DELETE
queries to indicate success/failure.
Changelog
Version
Description
5.3.0
This function now throws an E_DEPRECATED
notice.
4.0.6
This function is deprecated, do not use
this function. Use
mysql_select_db
and
mysql_query
instead.
Examples
Example 20.33.
mysql_db_query
alternative example
<?php
if (!$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
echo 'Could not connect to mysql';
exit;
}
if (!mysql_select_db('mysql_dbname', $link)) {
echo 'Could not select database';
exit;
}
$sql = 'SELECT foo FROM bar WHERE id = 42';
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result)) {
echo $row['foo'];
}
mysql_free_result($result);
?>
Notes
Note
Be aware that this function does NOT switch back to the database you were
connected before. In other words, you can't use this function to temporarily
run a sql query on another database, you would have to manually switch back.
Users are strongly encouraged to use the
database.table
syntax in their sql
queries or
mysql_select_db
instead of this function.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...