From 7cc925a924dc27087fdc575e771cc1a2a85fd0bf Mon Sep 17 00:00:00 2001 From: Gabor Hojtsy Date: Sat, 17 Nov 2001 12:59:11 +0000 Subject: [PATCH] Adding more see also information, description of MYSQL_... constants, more cross references, using &return.success; where applicable, more discussion of mysql_query() return value, etc. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@62632 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/mysql.xml | 174 ++++++++++++++++++++++++++------------------ 1 file changed, 103 insertions(+), 71 deletions(-) diff --git a/functions/mysql.xml b/functions/mysql.xml index c171843d0a..81f77cddb5 100644 --- a/functions/mysql.xml +++ b/functions/mysql.xml @@ -1,5 +1,5 @@ - + MySQL Functions MySQL @@ -324,7 +324,7 @@ mysql_close($link); Description - int mysql_create_db + bool mysql_create_db string database name resource @@ -338,7 +338,9 @@ mysql_close($link); database on the server associated with the specified link identifier. - + + &return.success; + MySQL create database example @@ -355,7 +357,7 @@ mysql_close($link); For downwards compatibility mysql_createdb - can also be used. + can also be used. This is deprecated, however. See also: mysql_drop_db. @@ -377,8 +379,8 @@ mysql_close($link); int row_number - - Returns: &true; on success, &false; on failure. + + &return.success; mysql_data_seek moves the internal row @@ -403,7 +405,7 @@ mysql_close($link); $result = mysql_query ($query) or die ("Query failed"); - # fetch rows in reverse order + // fetch rows in reverse order for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) { if (!mysql_data_seek ($result, $i)) { @@ -501,7 +503,7 @@ while ($i < $cnt) { - Returns: A positive MySQL result resource to the query result, + Returns a positive MySQL result resource to the query result, or &false; on error. @@ -547,16 +549,19 @@ while ($i < $cnt) { - Returns: &true; on success, &false; on failure. + &return.succes; mysql_drop_db attempts to drop (remove) an entire database from the server associated with the specified link identifier. + + For downward compatibility mysql_dropdb + can also be used. This is deprecated, however. + - See also: mysql_create_db. For downward - compatibility mysql_dropdb can also be used. + See also: mysql_create_db. @@ -724,25 +729,36 @@ echo mysql_errno().": ".mysql_error()."<BR>"; If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) - of the same name, you must the numeric index of the column or - make an alias for the column. + of the same name, you must use the numeric index of the column or + make an alias for the column. For aliased columns, you cannot + access the contents with the original column name (by using + 'field' in this example). -select t1.f1 as foo t2.f1 as bar from t1, t2 +select tone.field as foo ttwo.field as bar from tone, ttwo An important thing to note is that using - mysql_fetch_array is NOT significantly - slower than using mysql_fetch_row, while it - provides a significant added value. + mysql_fetch_array is not + significantly slower than using + mysql_fetch_row, while it provides + a significant added value. The optional second argument result_type in mysql_fetch_array is a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and - MYSQL_BOTH. (This feature was added in PHP 3.0.7) + MYSQL_BOTH. This feature was added in PHP 3.0.7. MYSQL_BOTH + is the default for this argument. + + + By using MYSQL_BOTH, you'll get an array with both associative + and number indices. Using MYSQL_ASSOC, you only get associative + indices (as mysql_fetch_assoc works), + using MYSQL_NUM, you only get number indices (as + mysql_fetch_row works). For further details, see also @@ -797,14 +813,17 @@ mysql_free_result ($result); If two or more columns of the result have the same field names, the last column will take precedence. To access the other - column(s) of the same name, you must use - mysql_fetch_array and have it return the - numeric indices as well. + column(s) of the same name, you either need to access the + result with numeric indices by using + mysql_fetch_row or add alias names. + See the example at the mysql_fetch_array + description about aliases. An important thing to note is that using - mysql_fetch_assoc is NOT significantly - slower than using mysql_fetch_row, while it + mysql_fetch_assoc is not + significantly slower than using + mysql_fetch_row, while it provides a significant added value. @@ -981,7 +1000,7 @@ mysql_free_result ($result); - Returns: An array that corresponds to the lengths of each field + Returns an array that corresponds to the lengths of each field in the last row fetched by mysql_fetch_row, or &false; on error. @@ -1031,7 +1050,9 @@ mysql_free_result ($result); The optional argument result_type is a constant and can take the following values: MYSQL_ASSOC, - MYSQL_NUM, and MYSQL_BOTH. + MYSQL_NUM, and MYSQL_BOTH. See + mysql_fetch_array for explanation + of these constants. Speed-wise, the function is identical to @@ -1074,7 +1095,7 @@ mysql_free_result ($result); - Returns: An array that corresponds to the fetched row, or &false; + Returns an array that corresponds to the fetched row, or &false; if there are no more rows. @@ -1127,7 +1148,7 @@ mysql_free_result ($result); For downward compatibility mysql_fieldflags - can also be used. + can also be used. This is deprecated, however. @@ -1190,7 +1211,7 @@ password For downwards compatibility mysql_fieldname - can also be used. + can also be used. This is deprecated, however. @@ -1217,7 +1238,7 @@ password For downward compatibility mysql_fieldlen - can also be used. + can also be used. This is deprecated, however. @@ -1272,7 +1293,7 @@ password For downward compatibility mysql_fieldtable - can also be used. + can also be used. This is deprecated, however. @@ -1330,7 +1351,7 @@ mysql_close(); For downward compatibility mysql_fieldtype - can also be used. + can also be used. This is deprecated, however. @@ -1344,7 +1365,7 @@ mysql_close(); Description - int mysql_free_result + bool mysql_free_result resource result @@ -1359,10 +1380,12 @@ mysql_close(); automatically freed at the end of the script's execution. - + + &returns.success; + For downward compatibility mysql_freeresult - can also be used. + can also be used. This is deprecated, however. @@ -1396,8 +1419,9 @@ mysql_close(); mysql_insert_id returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to - save the value for later, be sure to call mysql_insert_id() - immediately after the query that generates the value. + save the value for later, be sure to call + mysql_insert_id immediately after the + query that generates the value. @@ -1412,11 +1436,11 @@ mysql_close(); mysql_insert_id converts the return type of the native MySQL C API function mysql_insert_id() to a type of - long. If your AUTO_INCREMENT column has - a column type of BIGINT, the value returned by - mysql_insert_id will be incorrect. - Instead, use the internal MySQL SQL function - LAST_INSERT_ID(). + long (named int in PHP). + If your AUTO_INCREMENT column has a column type of BIGINT, + the value returned by mysql_insert_id + will be incorrect. Instead, use the internal MySQL SQL function + LAST_INSERT_ID() in an SQL query. @@ -1445,7 +1469,7 @@ mysql_close(); mysql_list_dbs will return a result pointer containing the databases available from the current mysql daemon. Use the mysql_tablename function to - traverse this result pointer. + traverse this result pointer, or any function for result tables. @@ -1479,7 +1503,7 @@ database3 For downward compatibility mysql_listdbs can - also be used. + also be used. This is deprecated however. See also mysql_db_name. @@ -1515,15 +1539,6 @@ database3 mysql_field_name, and mysql_field_type. - <function>mysql_list_fields</function> example @@ -1552,7 +1567,7 @@ field3 For downward compatibility mysql_listfields - can also be used. + can also be used. This is deprecated however.