From 70e670945e5bc66daa7f280ab7effc1edb96a0d6 Mon Sep 17 00:00:00 2001 From: Aidan Lister Date: Tue, 28 Dec 2004 12:06:25 +0000 Subject: [PATCH] Removed the second useless example, and replaced it with a best-practice query. Moved the information around so it was more continuous, not scattered from top to bottom (the result of many edits to add tidbits I assume). Also - applied the new docskel. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@175776 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysql/functions/mysql-query.xml | 197 ++++++++++++++-------- 1 file changed, 128 insertions(+), 69 deletions(-) diff --git a/reference/mysql/functions/mysql-query.xml b/reference/mysql/functions/mysql-query.xml index 0ff66e48fb..f423376958 100644 --- a/reference/mysql/functions/mysql-query.xml +++ b/reference/mysql/functions/mysql-query.xml @@ -1,49 +1,100 @@ - + mysql_query Send a MySQL query - - Description - - resourcemysql_query - stringquery - resourcelink_identifier - + + + &reftitle.description; + + resourcemysql_query + stringquery + resourcelink_identifier + - mysql_query sends a query to the currently + mysql_query sends a query (to the currently active database on the server that's associated with the - specified link identifier. If - link_identifier isn't specified, the last - opened link is assumed. If no link is open, the function tries - to establish a link as if mysql_connect was - called with no arguments, and use it. The result of the query is buffered. + specified link_identifier). - - - The query string should not end with a semicolon. - - + + + + &reftitle.parameters; - Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements - mysql_query - returns a resource identifier or &false; if the query was - not executed correctly. For other type of SQL statements, + + + query + + + A SQL query + + + The query string should not end with a semicolon. + + + + + link_identifier + + + A link identifier, as returned by mysql_connect. + + + If link_identifier isn't specified, the last + opened link is assumed. If no link is open, the function tries + to establish a link as if mysql_connect was + called with no arguments, and use it. The result of the query is buffered. + + + + + + + + + &reftitle.returnvalues; + + For SELECT, SHOW, DESCRIBE or EXPLAIN statements, + mysql_query + returns a resource on success, and &false; on + error. + + + For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query returns &true; on success - and &false; on error. A non-&false; return value - means that the query was legal and could be executed by - the server. It does not indicate anything about the number of - rows affected or returned. It is perfectly possible for a query - to succeed but affect no rows or return no rows. + and &false; on error. - The following query is syntactically invalid, so - mysql_query fails and returns &false;: + 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. + + + + + &reftitle.examples; + - <function>mysql_query</function> example + Invalid Query + + The following query is syntactically invalid, so + mysql_query fails and returns &false;. + ]]> - The following query is semantically invalid if - my_col is not a column in the table - my_tbl, so mysql_query - fails and returns &false;: - <function>mysql_query</function> + Valid Query + + The following query is valid, so mysql_query + returns a resource. + ]]> - - mysql_query will also fail and return &false; - if you don't have permission to access the table(s) referenced by - the query. - - - Assuming the query succeeds, you can call - 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. - - - Only for SELECT,SHOW,DESCRIBE or EXPLAIN statements, - mysql_query - returns a new result identifier that you can pass to - mysql_fetch_array and other - functions dealing with result tables. When you are done with the - result set, you can free the resources associated with it by - calling mysql_free_result. Although, the - memory will automatically be freed at the end of the script's - execution. - + + + + &reftitle.seealso; See also - mysql_num_rows, - mysql_affected_rows, mysql_unbuffered_query, - mysql_free_result, - mysql_fetch_array, - mysql_fetch_row, mysql_fetch_assoc, - mysql_result, - mysql_select_db and + mysql_error, + mysql_result and mysql_connect.