georg Thu Feb 26 13:32:30 2004 EDT
Modified files:
/phpdoc/en/reference/mysqli/functions mysqli-real-escape-string.xml
mysqli-report.xml
mysqli-rollback.xml
mysqli-select-db.xml
mysqli-sqlstate.xml
Log:
added samples
http://cvs.php.net/diff.php/phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml?r1=1.5&r2=1.6&ty=u
Index: phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml
diff -u phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml:1.5
phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml:1.6
--- phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml:1.5 Wed
Jan 28 18:18:42 2004
+++ phpdoc/en/reference/mysqli/functions/mysqli-real-escape-string.xml Thu Feb 26
13:32:30 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.5 $ -->
+<!-- $Revision: 1.6 $ -->
<refentry id="function.mysqli-real-escape-string">
<refnamediv>
<refname>mysqli_real_escape_string</refname>
@@ -47,6 +47,86 @@
<function>mysqli_character_set_name</function>.
</para>
</refsect1>
+ <refsect1>
+ <title>Example</title>
+ <example>
+ <title>Object oriented style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+$mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City");
+
+$city = "'s Hertogenbosch";
+
+/* this query will fail, cause we didn't escape $city */
+if (!$mysqli->query("INSERT into myCity (Name) VALUES ('$city')")) {
+ printf("Error: %s\n", $mysqli->sqlstate);
+}
+
+$city = $mysqli->real_escape_string($city);
+
+/* this query with escaped $city will work */
+if ($mysqli->query("INSERT into myCity (Name) VALUES ('$city')")) {
+ printf("%d Row inserted.\n", $mysqli->affected_rows);
+}
+
+$mysqli->close();
+?>
+]]>
+ </programlisting>
+ </example>
+ <example>
+ <title>Procedural style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$link = mysqli_connect("localhost", "my_user", "my_password", "world");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
+
+$city = "'s Hertogenbosch";
+
+/* this query will fail, cause we didn't escape $city */
+if (!mysqli_query($link, "INSERT into myCity (Name) VALUES ('$city')")) {
+ printf("Error: %s\n", mysqli_sqlstate($link));
+}
+
+$city = mysqli_real_escape_string($link, $city);
+
+/* this query with escaped $city will work */
+if (mysqli_query($link, "INSERT into myCity (Name) VALUES ('$city')")) {
+ printf("%d Row inserted.\n", mysqli_affected_rows($link));
+}
+
+mysqli_close($link);
+?>
+]]>
+ </programlisting>
+ </example>
+ <para>
+ The above examples would produce the following output:
+ </para>
+ <screen>
+<![CDATA[
+Error: 42000
+1 Row inserted.
+]]>
+ </screen>
+ </refsect1>
</refentry>
<!-- Keep this comment at the end of the file
http://cvs.php.net/diff.php/phpdoc/en/reference/mysqli/functions/mysqli-report.xml?r1=1.3&r2=1.4&ty=u
Index: phpdoc/en/reference/mysqli/functions/mysqli-report.xml
diff -u phpdoc/en/reference/mysqli/functions/mysqli-report.xml:1.3
phpdoc/en/reference/mysqli/functions/mysqli-report.xml:1.4
--- phpdoc/en/reference/mysqli/functions/mysqli-report.xml:1.3 Sun Feb 22 16:46:41
2004
+++ phpdoc/en/reference/mysqli/functions/mysqli-report.xml Thu Feb 26 13:32:30
2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
<refentry id="function.mysqli-report">
<refnamediv>
<refname>mysqli_report</refname>
@@ -65,54 +65,30 @@
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
-
<?php
-
-$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
-
+/* activate reporting */
mysqli_report(MYSQLI_REPORT_ALL);
-$mysqli->query("DROP TABLE IF EXISTS report");
-$mysqli->query("CREATE TABLE report (a int, b int, index(a))");
+$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
-$mysqli->query("INSERT INTO report VALUES (1,1), (2,2), (1,3), (2,4), (6,5)");
-
-/* this should report syntax error */
-$mysqli->query("UPDAE report SET a=a+1 WHERE b=3");
-
-/* this should report index warning */
-$mysqli->query("UPDATE report SET a=a+1 WHERE b=3");
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+/* this query should report an error */
+$result = $mysqli->query("SELECT Name FROM Nonexistingtable WHERE population >
50000");
+
+/* this query should report a warning */
+$result = $mysqli->query("SELECT Name FROM City WHERE population > 50000");
+$result->close();
$mysqli->close();
?>
]]>
</programlisting>
</example>
- <example>
- <title>Object oriented style</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-$link = mysqli_connect("localhost", "my_user", "my_password", "test");
-
-mysqli_report(MYSQLI_REPORT_ALL);
-
-mysqli_query($link, "DROP TABLE IF EXISTS report");
-mysqli_query($link, "CREATE TABLE report (a int, b int, index(a))");
-
-mysqli_query($link, "INSERT INTO report VALUES (1,1), (2,2), (1,3), (2,4), (6,5)");
-
-/* this should report syntax error */
-mysqli_query($link, "UPDAE report SET a=a+1 WHERE b=3");
-
-/* this should report index warning */
-mysqli_query($link, "UPDATE report SET a=a+1 WHERE b=3");
-
-mysqli_close($link);
-?>
-]]>
- </programlisting>
- </example>
</para>
</refsect1>
</refentry>
http://cvs.php.net/diff.php/phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml
diff -u phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml:1.4
phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml:1.5
--- phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml:1.4 Fri Feb 20
03:54:11 2004
+++ phpdoc/en/reference/mysqli/functions/mysqli-rollback.xml Thu Feb 26 13:32:30
2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<refentry id="function.mysqli-rollback">
<refnamediv>
<refname>mysqli_rollback</refname>
@@ -39,63 +39,118 @@
</para>
</refsect1>
<refsect1>
- <title>Examples</title>
- <para>
- <example>
- <title>Object oriented style</title>
- <programlisting role="php">
+ <title>Example</title>
+ <example>
+ <title>Object oriented style</title>
+ <programlisting role="php">
<![CDATA[
<?php
+$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
-$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
-
-$mysqli->query("DROP TABLE IF EXISTS ta_sample");
-$mysqli->query("CREATE TABLE ta_sample (a int) TYPE=InnoDB");
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
-/* set autocommit to off */
+/* disable autocommit */
$mysqli->autocommit(FALSE);
-/* Insert some values */
-$mysqli->query("INSERT INTO ta_sample VALUES (1)");
-$mysqli->query("INSERT INTO ta_sample VALUES (1)");
+$mysqli->query("CREATE TABLE myCity LIKE City");
+$mysqli->query("ALTER TABLE myCity Type=InnoDB");
+$mysqli->query("INSERT INTO myCity SELECT * FROM City LIMIT 50");
+
+/* commit insert */
+$mysqli->commit();
+
+/* delete all rows */
+$mysqli->query("DELETE FROM myCity");
+
+if ($result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
+ $row = $result->fetch_row();
+ printf("%d rows in table myCity.\n", $row[0]);
+ /* Free result */
+ $result->close();
+}
-/* rollback transaction */
+/* Rollback */
$mysqli->rollback();
-/* close connection */
+if ($result = $mysqli->query("SELECT COUNT(*) FROM myCity")) {
+ $row = $result->fetch_row();
+ printf("%d rows in table myCity (after rollback).\n", $row[0]);
+ /* Free result */
+ $result->close();
+}
+
+/* Drop table myCity */
+$mysqli->query("DROP TABLE myCity");
+
$mysqli->close();
?>
]]>
- </programlisting>
- </example>
- <example>
- <title>Procedural style</title>
- <programlisting role="php">
+ </programlisting>
+ </example>
+ <example>
+ <title>Procedural style</title>
+ <programlisting role="php">
<![CDATA[
<?php
+$link = mysqli_connect("localhost", "my_user", "my_password", "world");
-$link = mysqli_connect("localhost", "my_user", "my_password", "test");
-
-mysqli_query($link, "DROP TABLE IF EXISTS ta_sample");
-mysqli_query($link, "CREATE TABLE ta_sample (a int) TYPE=InnoDB");
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
-/* set autocommit to off */
+/* disable autocommit */
mysqli_autocommit($link, FALSE);
-/* Insert some values */
-mysqli_query($link, "INSERT INTO ta_sample VALUES (1)");
-mysqli_query($link, "INSERT INTO ta_sample VALUES (1)");
+mysqli_query($link, "CREATE TABLE myCity LIKE City");
+mysqli_query($link, "ALTER TABLE myCity Type=InnoDB");
+mysqli_query($link, "INSERT INTO myCity SELECT * FROM City LIMIT 50");
+
+/* commit insert */
+mysqli_commit($link);
+
+/* delete all rows */
+mysqli_query($link, "DELETE FROM myCity");
+
+if ($result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
+ $row = mysqli_fetch_row($result);
+ printf("%d rows in table myCity.\n", $row[0]);
+ /* Free result */
+ mysqli_free_result($result);
+}
-/* rollback transaction */
+/* Rollback */
mysqli_rollback($link);
-/* close connection */
+if ($result = mysqli_query($link, "SELECT COUNT(*) FROM myCity")) {
+ $row = mysqli_fetch_row($result);
+ printf("%d rows in table myCity (after rollback).\n", $row[0]);
+ /* Free result */
+ mysqli_free_result($result);
+}
+
+/* Drop table myCity */
+mysqli_query($link, "DROP TABLE myCity");
+
mysqli_close($link);
?>
]]>
- </programlisting>
- </example>
+ </programlisting>
+ </example>
+ <para>
+ The above examples would produce the following output:
</para>
+ <screen>
+<![CDATA[
+0 rows in table myCity.
+50 rows in table myCity (after rollback).
+]]>
+ </screen>
</refsect1>
</refentry>
http://cvs.php.net/diff.php/phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml?r1=1.6&r2=1.7&ty=u
Index: phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml
diff -u phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml:1.6
phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml:1.7
--- phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml:1.6 Wed Jan 28
18:18:42 2004
+++ phpdoc/en/reference/mysqli/functions/mysqli-select-db.xml Thu Feb 26 13:32:30
2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.6 $ -->
+<!-- $Revision: 1.7 $ -->
<refentry id="function.mysqli-select-db">
<refnamediv>
<refname>mysqli_select_db</refname>
@@ -39,6 +39,88 @@
<function>mysqli_real_connect</function>
</para>
</refsect1>
+ <refsect1>
+ <title>Example</title>
+ <example>
+ <title>Object oriented style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+/* return name of current default database */
+if ($result = $mysqli->query("SELECT DATABASE()")) {
+ $row = $result->fetch_row();
+ printf("Default database is %s.\n", $row[0]);
+ $result->close();
+}
+
+/* change db to world db */
+$mysqli->select_db("world");
+
+/* return name of current default database */
+if ($result = $mysqli->query("SELECT DATABASE()")) {
+ $row = $result->fetch_row();
+ printf("Default database is %s.\n", $row[0]);
+ $result->close();
+}
+
+$mysqli->close();
+?>
+]]>
+ </programlisting>
+ </example>
+ <example>
+ <title>Procedural style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$link = mysqli_connect("localhost", "my_user", "my_password", "test");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+/* return name of current default database */
+if ($result = mysqli_query($link, "SELECT DATABASE()")) {
+ $row = mysqli_fetch_row($result);
+ printf("Default database is %s.\n", $row[0]);
+ mysqli_free_result($result);
+}
+
+/* change db to world db */
+mysqli_select_db($link, "world");
+
+/* return name of current default database */
+if ($result = mysqli_query($link, "SELECT DATABASE()")) {
+ $row = mysqli_fetch_row($result);
+ printf("Default database is %s.\n", $row[0]);
+ mysqli_free_result($result);
+}
+
+mysqli_close($link);
+?>
+]]>
+ </programlisting>
+ </example>
+ <para>
+ The above examples would produce the following output:
+ </para>
+ <screen>
+<![CDATA[
+Default database is test.
+Default database is world.
+]]>
+ </screen>
+ </refsect1>
</refentry>
<!-- Keep this comment at the end of the file
http://cvs.php.net/diff.php/phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml?r1=1.1&r2=1.2&ty=u
Index: phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml
diff -u phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml:1.1
phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml:1.2
--- phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml:1.1 Sun Feb 8
08:14:42 2004
+++ phpdoc/en/reference/mysqli/functions/mysqli-sqlstate.xml Thu Feb 26 13:32:30
2004
@@ -1,19 +1,100 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.1 $ -->
+<!-- $Revision: 1.2 $ -->
<refentry id="function.mysqli-sqlstate">
<refnamediv>
<refname>mysqli_sqlstate</refname>
+ <refname>mysqli->sqlstate</refname>
<refpurpose>Returns the SQLSTATE error from previous MySQL operation.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
- <methodsynopsis>
- <type>string</type><methodname>mysqli_sqlstate</methodname>
- <methodparam><type>object</type><parameter>link</parameter></methodparam>
- </methodsynopsis>
+ <methodsynopsis>
+ <type>string</type><methodname>mysqli_sqlstate</methodname>
+ <methodparam><type>object</type><parameter>link</parameter></methodparam>
+ </methodsynopsis>
+ <para>
+ Returns a string containing the SQLSTATE error code for the last error.
+ The error code consists of five characters. <literal>'00000'</literal> means no
error.
+ The values are specified by ANSI SQL and ODBC. For a list of possible values,
see
+ <ulink url="&url.mysql.docs.error;">&url.mysql.docs.error;</ulink>.
+ </para>
+ <note>
+ <para>
+ Note that not all MySQL errors are yet mapped to SQLSTATE's.
+ The value <literal>HY000</literal> (general error) is used for unmapped errors.
+ </para>
+ </note>
+ </refsect1>
+ <refsect1>
+ <title>Return values</title>
+ <para>
+ Returns a string containing the SQLSTATE error code for the last error.
+ The error code consists of five characters. <literal>'00000'</literal> means no
error.
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <function>mysqli_errno</function>,
+ <function>mysqli_error</function>
+ </para>
+ </refsect1>
+ <refsect1>
+ <title>Example</title>
+ <example>
+ <title>Object oriented style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
+
+/* Table City already exists, so we should get an error */
+if (!$mysqli->query("CREATE TABLE City (ID INT, Name VARCHAR(30))")) {
+ printf("Error - SQLSTATE %s.\n", $mysqli->sqlstate);
+}
+
+$mysqli->close();
+?>
+]]>
+ </programlisting>
+ </example>
+ <example>
+ <title>Procedural style</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$link = mysqli_connect("localhost", "my_user", "my_password", "world");
+
+/* check connection */
+if (mysqli_connect_errno()) {
+ printf("Connect failed: %s\n", mysqli_connect_error());
+ exit();
+}
- &warn.undocumented.func;
+/* Table City already exists, so we should get an error */
+if (!mysqli_query($link, "CREATE TABLE City (ID INT, Name VARCHAR(30))")) {
+ printf("Error - SQLSTATE %s.\n", mysqli_sqlstate($link));
+}
+mysqli_close($link);
+?>
+]]>
+ </programlisting>
+ </example>
+ <para>
+ The above examples would produce the following output:
+ </para>
+ <screen>
+<![CDATA[
+Error - SQLSTATE 42S01.
+]]>
+ </screen>
</refsect1>
</refentry>