diff --git a/functions/mysql.xml b/functions/mysql.xml index 95476fccd9..b485d0d4c2 100644 --- a/functions/mysql.xml +++ b/functions/mysql.xml @@ -116,6 +116,18 @@ mysql_close will not close persistent links generated by mysql_pconnect. + + MySQL close example + +<?php + $link = mysql_connect ("kraemer", "marliesle", "secret") { + or die ("Could not connect"); + } + print ("Connected successfully"); + mysql_close ($link); +?> + + See also: mysql_connect, and mysql_pconnect. @@ -186,6 +198,18 @@ the script ends, unless it's closed earlier by explicitly calling mysql_close. + + MySQL connect example + +<?php + $link = mysql_connect ("kraemer", "marliesle", "secret") { + or die ("Could not connect"); + } + print ("Connected successfully"); + mysql_close ($link); +?> + + See also mysql_pconnect, and mysql_close. @@ -214,6 +238,21 @@ database on the server associated with the specified link identifier. + + MySQL create database example + +<?php + $link = mysql_pconnect ("kron", "jutta", "geheim") { + or die ("Could not connect"); + } + if (mysql_create_db ("my_db")) { + print ("Database created successfully\n"); + } else { + printf ("Error creating database: %s\n", mysql_error ()); + } +?> + + See also: mysql_drop_db. For downwards compatibility mysql_createdb can also be @@ -246,6 +285,42 @@ Row_number starts at 0. + + + MySQL data seek example + +<?php + $link = mysql_pconnect ("kron", "jutta", "geheim") { + or die ("Could not connect"); + } + + mysql_select_db ("samp_db") { + or die ("Could not select database"); + } + + $query = "SELECT last_name, first_name FROM friends"; + $result = mysql_query ($query) { + or die ("Query failed"); + } + + # fetch rows in reverse order + + for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) { + if (!mysql_data_seek ($result, $i)) { + printf ("Cannot seek to row %d\n", $i); + continue; + } + + if(!($row = mysql_fetch_object ($result))) + continue; + + printf ("%s %s<BR>\n", $row->last_name, $row->first_name); + } + + mysql_free_result ($result); +?> + +