From c864e2b53159558dbe1c675c5391119e7ca0d7a5 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sat, 21 Feb 2004 08:44:40 +0000 Subject: [PATCH] fixed return value in mysqli_fetch_field_direct added samples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@151980 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysqli/functions/mysqli-execute.xml | 136 ++++++++++----- .../mysqli/functions/mysqli-fetch-array.xml | 157 ++++++++++-------- .../mysqli/functions/mysqli-fetch-assoc.xml | 110 ++++++------ .../functions/mysqli-fetch-field-direct.xml | 71 +++++++- 4 files changed, 303 insertions(+), 171 deletions(-) diff --git a/reference/mysqli/functions/mysqli-execute.xml b/reference/mysqli/functions/mysqli-execute.xml index fcffbd59fd..746c8d3f93 100644 --- a/reference/mysqli/functions/mysqli-execute.xml +++ b/reference/mysqli/functions/mysqli-execute.xml @@ -1,5 +1,5 @@ - + mysqli_execute @@ -44,49 +44,6 @@ Return values &return.success; - - Example - - - Using the mysqli_execute function - - -]]> - - - - See also @@ -94,6 +51,97 @@ mysqli_bind_param. + + Example + + + Object oriented style + +query("DROP TABLE IF EXISTS friends"); +$mysqli->query("CREATE TABLE friends (id int, name varchar(20))"); + +/* Prepare an insert statement */ +$query = "INSERT INTO friends VALUES(?, ?)"; +$stmt = $mysqli->prepare($query); + +$stmt->bind_param("is", $val1, $val2); + +$val1 = 1; +$val2 = 'Miller'; + +/* Execute the statement */ +$stmt->execute(); + +$val1 = 2; +$val2 = 'Wagner'; + +/* Execute the statement */ +$stmt->execute(); + +$stmt->close(); + +/* Return the affected rows for the statement */ +if ($result = $mysqli->query("SELECT id,name FROM friends")) { + while ($row = $result->fetch_row()) { + printf("ID: %s Name: %s\n", $row[0], $row[1]); + } + $result->close(); +} + +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_fetch_array @@ -24,7 +24,7 @@ - Returns an array that corresponds to the fetched row or &false; if there are no more rows for the + Returns an array that corresponds to the fetched row or &null; if there are no more rows for the database connection represented by the link parameter. @@ -55,72 +55,7 @@ Return values - Returns an array that corresponds to the fetched row or &false; if there are no more rows in resultset. - - - - Example - - - mysqli_fetch_array with MYSQLI_NUM - - -]]> - - - - mysqli_fetch_array with MYSQLI_ASSOC - - -]]> - - - - mysqli_fetch_array with MYSQLI_BOTH - - -]]> - - + Returns an array that corresponds to the fetched row or &null; if there are no more rows in resultset. @@ -131,6 +66,92 @@ mysqli_fetch_object. + + Example + + + Object oriented style + +query("DROP TABLE IF EXISTS friends"); +$mysqli->query("CREATE TABLE friends (id int, name varchar(20))"); + +$mysqli->query("INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')"); + +$result = $mysqli->query( "SELECT id, name FROM friends"); + +/* numeric array */ +while ($row = $result->fetch_array(MYSQLI_NUM)) { + printf ("ID: %s Name: %s\n", $row[0], $row[1]); +} +$result->close(); + +$result = $mysqli->query("SELECT id, name FROM friends"); + +/* associative array */ +while ($row = $result->fetch_array(MYSQLI_ASSOC)) { + printf ("ID: %s Name: %s\n", $row["id"], $row["name"]); +} +$result->close(); + +$result = $mysqli->query("SELECT id, name FROM friends"); + +/* associative and numeric array */ +while ($row = $result->fetch_array(MYSQLI_BOTH)) { + printf ("ID: %s Name: %s\n", $row[0], $row["name"]); +} +$result->close(); + +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_fetch_assoc @@ -23,7 +23,7 @@ - Returns an associative array that corresponds to the fetched row or &false; if there are + Returns an associative array that corresponds to the fetched row or &null; if there are no more rows. @@ -44,62 +44,9 @@ Return values - Returns an array that corresponds to the fetched row or &false; if there are no more rows in resultset. + Returns an array that corresponds to the fetched row or &null; if there are no more rows in resultset. - - Example - - An expanded <function>mysqli_fetch_assoc</function> example - - -]]> - - - See also @@ -108,6 +55,57 @@ mysqli_fetch_object. + + Example + + Object oriented style + +query( "DROP TABLE IF EXISTS friends"); +$mysqli->query( "CREATE TABLE friends (id int, name varchar(20))"); + +$mysqli->query( "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')"); + +$result = $mysqli->query( "SELECT id, name FROM friends"); + +while ($row = $result->fetch_assoc()) { + printf ("ID: %s Name: %s\n", $row["id"], $row["name"]); +} +$result->close(); + +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + mysqli_fetch_field_direct @@ -26,7 +26,7 @@ - mysqli_fetch_field_direct returns an associative array which contains + mysqli_fetch_field_direct returns an object which contains field definition informations from specified resultset. The value of fieldnr must be in the range from 0 to number of fields - 1. @@ -34,7 +34,7 @@ Return values - Returns an associative array which contains field definition informations or &false; if no field information + Returns an object which contains field definition informations or &false; if no field information for specified fieldnr is available. @@ -46,6 +46,71 @@ mysqli_fetch_fields + + Example + + Object oriented style + +query( "DROP TABLE IF EXISTS friends"); +$mysqli->query( "CREATE TABLE friends (id int, name varchar(20))"); + +$mysqli->query( "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')"); + +$result = $mysqli->query( "SELECT id, name FROM friends"); + +/* Get field information for column 'name' */ +$finfo = $result->fetch_field_direct(1); + +printf("Name: %s\n", $finfo->name); +printf("Table: %s\n", $finfo->table); +printf("Default: %s\n", $finfo->def); +printf("max. Len: %d\n", $finfo->max_length); +printf("Flags: %d\n", $finfo->flags); +printf("Type: %d\n", $finfo->type); + +$result->close(); + +$mysqli->close(); +?> +]]> + + + + Procedural style + +name); +printf("Table: %s\n", $finfo->table); +printf("Default: %s\n", $finfo->def); +printf("max. Len: %d\n", $finfo->max_length); +printf("Flags: %d\n", $finfo->flags); +printf("Type: %d\n", $finfo->type); + +mysqli_free_result($result); + +mysqli_close($link); +?> +]]> + + +