mysql_db_query
mysql_db_query
Selects a database and executes a query on it
Waarschuwing: >
mysqli_select_db``PDO::__construct
**mysql_db_query** string $database string $query resource $link_identifier
selects a database, and executes a
query on it.
mysql_db_query
databaseThe name of the database that will be selected.
queryThe MySQL query.
Data inside the query should be .
properly escaped
Returns a positive MySQL result resource to the query result,
or false on error. The function also returns true/false for
//
queries to indicate success/failure.
INSERT``UPDATE``DELETE
Voorbeeld: 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);
?>
Opmerking: > Be aware that this function does switch back to the database you were connected before. In other words, you can't use this function to run a sql query on another database, you would have to manually switch back. Users are strongly encouraged to use the syntax in their sql queries or instead of this function. NOT**temporarily
database.table``mysql_select_db
mysql_query``mysql_select_db