Name
mysql_query
Synopsis
qresource mysql_query(stringquery
[, cresourceconnection
])
Executes an
SQL query
and (usually) returns a query
resource handle that can be used to retrieve the result set. The
query
statement does not need to be
terminated with a semicolon, and any valid SQL statement is
permitted. If the connection
resource
handle parameter is omitted, the last opened connection that is still
open is assumed. If no connection is open, an attempt is made to open
one, just as when mysql_connect( )
is issued with
no parameters.
On success, the function never returns a false
value. For SELECT
, SHOW
,
EXPLAIN
, or DESCRIBE
queries,
the function returns a query result resource that can be used to
fetch data. For other SQL queries, the function returns
true
on success. The function returns
false
on failure.
Example
<?php $query = "SELECT * FROM people WHERE people_id LIKE 'h%'"; $connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("wedding", $connection); $result = mysql_query($query, $connection); while ($row = mysql_fetch_array($result)) echo $row["people_id"] . "\n"; ?>
Get Managing & Using MySQL, 2nd Edition 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.