Original MySQL API (
Mysql
)
2295
Parameters
query
An SQL query
The query string should not end with a semicolon. Data inside the
query should be
properly escaped
.
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
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset,
mysql_query
returns a resource on success, or
FALSE
on error.
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc,
mysql_query
returns
TRUE
on success or
FALSE
on error.
The returned result resource should be passed to
mysql_fetch_array
, and other functions for
dealing with result tables, to access the returned data.
Use
mysql_num_rows
to find out how many rows were returned for a SELECT statement or
mysql_affected_rows
to find out how many rows were affected by a DELETE, INSERT, REPLACE,
or UPDATE statement.
mysql_query
will also fail and return
FALSE
if the user does not have permission to access the
table(s) referenced by the query.
Examples
Example 20.67. Invalid Query
The following query is syntactically invalid, so
mysql_query
fails and returns
FALSE
.
<?php
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>
Example 20.68. Valid Query
The following query is valid, so
mysql_query
returns a resource.
<?php
// This could be supplied by a user, for example
$firstname = 'fred';
$lastname = 'fox';
// Formulate Query
// This is the best way to perform an SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT firstname, lastname, address, age FROM friends
WHERE firstname='%s' AND lastname='%s'",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...