From 3eb2dcea98fbf3ef3570d5909a1a0e0a0ca876a3 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sun, 22 Feb 2004 09:40:50 +0000 Subject: [PATCH] added more samples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@152070 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../functions/mysqli-fetch-field-direct.xml | 53 +++++++- .../mysqli/functions/mysqli-fetch-field.xml | 86 ++++++++++-- .../mysqli/functions/mysqli-fetch-fields.xml | 124 +++++++++++++++++- .../mysqli/functions/mysqli-fetch-lengths.xml | 69 +++++++++- .../mysqli/functions/mysqli-fetch-object.xml | 59 ++++++++- .../mysqli/functions/mysqli-fetch-row.xml | 59 ++++++++- reference/mysqli/functions/mysqli-fetch.xml | 69 +++++++++- .../mysqli/functions/mysqli-field-count.xml | 72 +++++++++- .../mysqli/functions/mysqli-field-seek.xml | 80 ++++++++++- .../mysqli/functions/mysqli-field-tell.xml | 74 ++++++++++- 10 files changed, 722 insertions(+), 23 deletions(-) diff --git a/reference/mysqli/functions/mysqli-fetch-field-direct.xml b/reference/mysqli/functions/mysqli-fetch-field-direct.xml index fc242a2c63..1e708cde77 100644 --- a/reference/mysqli/functions/mysqli-fetch-field-direct.xml +++ b/reference/mysqli/functions/mysqli-fetch-field-direct.xml @@ -1,5 +1,5 @@ - + mysqli_fetch_field_direct @@ -37,6 +37,57 @@ Returns an object which contains field definition informations or &false; if no field information for specified fieldnr is available. + + + Object attributes + + + + Attribute + Description + + + + + name + The name of the column + + + orgname + Original column name if an alias was specified + + + table + The name of the table this field belongs to (if not calculated) + + + orgtable + Original table name if an alias was specified + + + def + The default value for this field, represented as a string + + + max_length + The maximum width of the field for the result set. + + + flags + An integer representing the bit-flags for the field. + + + type + The data type used for this field + + + decimals + The number of decimals used (for integer fields) + + + +
+
See also diff --git a/reference/mysqli/functions/mysqli-fetch-field.xml b/reference/mysqli/functions/mysqli-fetch-field.xml index a28fb14a7e..3c304b0407 100644 --- a/reference/mysqli/functions/mysqli-fetch-field.xml +++ b/reference/mysqli/functions/mysqli-fetch-field.xml @@ -1,5 +1,5 @@ - + mysqli_fetch_field @@ -29,6 +29,13 @@ the attributes of the current column or &false; if there are no more columns in the result set. + + + Return values + + Returns an object which contains field definition informations or &false; if no field information + is available. + Object attributes @@ -81,21 +88,82 @@
- - Return values - - Returns an object which contains field definition informations or &false; if no field information - is available. - - See also mysqli_num_fields mysqli_fetch_field_direct mysqli_fetch_fields + mysqli_field_seek - + + + 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 all columns */ +while ($finfo = $result->fetch_field()) { + 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); +?> +]]> + + + +
+ mysqli_fetch_fields @@ -36,6 +36,57 @@ Returns an array of objects which contains field definition informations or &false; if no field information is available. + + + Object attributes + + + + Attribute + Description + + + + + name + The name of the column + + + orgname + Original column name if an alias was specified + + + table + The name of the table this field belongs to (if not calculated) + + + orgtable + Original table name if an alias was specified + + + def + The default value for this field, represented as a string + + + max_length + The maximum width of the field for the result set. + + + flags + An integer representing the bit-flags for the field. + + + type + The data type used for this field + + + decimals + The number of decimals used (for integer fields) + + + +
+
See also @@ -45,6 +96,77 @@ mysqli_fetch_field_direct + + Example + + + Object oriented style + +name); + printf("Table: %s\n", $finfo[$i]->table); + printf("Default: %s\n", $finfo[$i]->def); + printf("max. Len: %d\n", $finfo[$i]->max_length); + printf("Flags: %d\n", $finfo[$i]->flags); + printf("Type: %d\n", $finfo[$i]->type); +} + +mysqli_free_result($result); + +mysqli_close($link); +?> +]]> + + + + Procedural 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_fields(); + +for ($i=0; $i < count($finfo); $i++) { + printf("Name: %s\n", $finfo[$i]->name); + printf("Table: %s\n", $finfo[$i]->table); + printf("Default: %s\n", $finfo[$i]->def); + printf("max. Len: %d\n", $finfo[$i]->max_length); + printf("Flags: %d\n", $finfo[$i]->flags); + printf("Type: %d\n", $finfo[$i]->type); +} + +$result->close(); + +$mysqli->close(); +?> +]]> + + + +
+ mysqli_fetch_lengths - result->fetch_lengths + result->lengths Returns the lengths of the columns of the current row in the result set @@ -16,7 +16,7 @@ Object oriented style (property): result - mixedfetch_lengths + mixedlengths The mysqli_fetch_lengths function returns an array containing the @@ -37,6 +37,69 @@ all rows in the result. + + 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"); + +$row = $result->fetch_row(); + +/* Print field lengths */ +for ($i=0; $i < count($result->lengths); $i++) { + printf("Field %d has length %d\n", $i, $result->lengths[$i]); +} + +$result->close(); + +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_fetch_object @@ -31,7 +31,7 @@ Return values - Returns an object or &false; if an error occured. + Returns an object that corresponds to the fetched row or &null; if there are no more rows in resultset. &database.field-case; @@ -43,6 +43,61 @@ mysqli_fetch_row. + + Example + + + Object oriented style + +id, $obj->name); + +mysqli_free_result($result); +mysqli_close($link); +?> +]]> + + + + Procedural 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"); + +/* fetch object */ +$obj = $result->fetch_object(); + +printf("Id: %d Name: %s\n", $obj->id, $obj->name); + +$result->close(); +$mysqli->close(); +?> +]]> + + + + + mysqli_fetch_row @@ -37,7 +37,7 @@ Return values mysqli_fetch_row returns an array that corresponds to the fetched row - or &false; if there are no more rows in result set. + or &null; if there are no more rows in result set. @@ -48,6 +48,61 @@ 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"); + +/* fetch object */ +$row = $result->fetch_row(); + +printf("Id: %d Name: %s\n", $row[0], $row[1]); + +$result->close(); +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_fetch @@ -70,6 +70,73 @@ mysqli_bind_result + + 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')"); + +$stmt = $mysqli->prepare( "SELECT id, name FROM friends"); + +/* execute statement */ +$stmt->execute(); + +/* bind result variables */ +$stmt->bind_result($column1, $column2); + +/* fetch result */ +while ($stmt->fetch()) { + printf("Id: %d Name: %s\n", $column1, $column2); +} + +$stmt->close(); +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_field_count - mysql->field_cont + mysql->field_count Returns the number of columns for the most recent query @@ -34,6 +34,74 @@ Return values An integer representing the number of fields in a result set + + 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')"); + + +$mysqli->real_query($HTTP_POST_VARS['query']); + +if (mysql_field_count($link)) { + /* this was a select/show or describe query */ + $result = $mysqli->store_result(); + + /* process resultset */ + $row = $result->fetch_row(); + + /* free resultset */ + $result->close(); +} + +/* close connection */ +$mysqli->close(); +?> +]]> + + + + Procedural style + + +]]> + + + + + mysqli_field_seek @@ -39,6 +39,84 @@ mysqli_field_seek returns previuos value of field cursor. + + See also + + mysqli_fetch_field + + + + 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"); + +/* set field pointer to column name */ +$result->field_seek(1); + +/* fetch field information */ +$finfo = $result->fetch_field(); +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); +?> +]]> + + + + + mysqli_field_tell @@ -42,6 +42,78 @@ mysqli_field_seek + + 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 ($finfo = mysqli_fetch_field($result)) { + /* get field pointer position */ + $fieldnr = mysqli_field_tell($result); + printf("Fieldnr: %d\n", $fieldnr); + + 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 + +fetch_field()) { + /* get field pointer position */ + $fieldnr = $result->current_field; + printf("Fieldnr: %d\n", $fieldnr); + 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); +} + +mysqli_free_result($result); + +mysqli_close($link); +?> +]]> + + + +