mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
PHP syntax highlighting
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@322202 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
122f551481
commit
cbe13b0842
5 changed files with 88 additions and 31 deletions
|
@ -115,6 +115,7 @@ $cl = $ob1->getClosure();
|
|||
echo $cl(), "\n";
|
||||
$cl = $cl->bindTo($ob2);
|
||||
echo $cl(), "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
|
|
|
@ -34,12 +34,12 @@
|
|||
<para>
|
||||
Specifies the request function that should match the following prototype:
|
||||
|
||||
<programlisting role="php"><![CDATA[
|
||||
<programlisting><![CDATA[
|
||||
mixed execute(mixed data);
|
||||
]]></programlisting>
|
||||
<parameter>callback</parameter> is event completion callback that should match the following
|
||||
prototype:
|
||||
<programlisting role="php"><![CDATA[
|
||||
<programlisting><![CDATA[
|
||||
void callback(mixed data, mixed result);
|
||||
]]></programlisting>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
For example, a modifying update could add a new field to a document.
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
||||
<?php
|
||||
/** suppose documents look like:
|
||||
* {"username" : "...", "password" : "...", "email" : "..."}
|
||||
*/
|
||||
|
@ -35,7 +35,7 @@ $coll->update(array("username" => "joe"), array('$set' => array("twitter" => "@j
|
|||
/** now the document will look like:
|
||||
* {"username" : "joe", "password" : "...", "email" : "...", "twitter" : "@joe4153"}
|
||||
*/
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
@ -52,7 +52,7 @@ $coll->update(array("username" => "joe"), array('$set' => array("twitter" => "@j
|
|||
document.
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
||||
<?php
|
||||
/** suppose documents look like:
|
||||
* {"username" : "...", "password" : "...", "email" : "..."}
|
||||
*/
|
||||
|
@ -70,7 +70,7 @@ $coll->update(array("username" => "joe"), array("userId" => 12345, "info" => arr
|
|||
* "likes" : []
|
||||
* }
|
||||
*/
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
||||
<?php
|
||||
$collection->insert($someDoc);
|
||||
$collection->update($criteria, $newObj);
|
||||
$collection->insert($somethingElse);
|
||||
$collection->remove($something, array("safe" => true));
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
|
@ -62,9 +62,9 @@ $collection->remove($something, array("safe" => true));
|
|||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
|
||||
<?php
|
||||
$collection->insert($someDoc, array("safe" => 3));
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<title>Easy migration from the old mysql extension</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = mysqli_connect("example.com", "user", "password", "database");
|
||||
$res = mysqli_query($mysqli, "SELECT 'Please, do not use ' AS _msg FROM DUAL");
|
||||
$row = mysqli_fetch_assoc($res);
|
||||
|
@ -44,6 +45,7 @@ mysql_select_db("test");
|
|||
$res = mysql_query("SELECT 'the mysql extension for new developments.' AS _msg FROM DUAL", $mysql);
|
||||
$row = mysql_fetch_assoc($res);
|
||||
echo $row['_msg'];
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -73,6 +75,7 @@ Please, do not use the mysql extension for new developments.
|
|||
<title>Object-oriented and procedural interface</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = mysqli_connect("example.com", "user", "password", "database");
|
||||
if (mysqli_connect_errno($mysqli))
|
||||
echo "Failed to connect to MySQL: " . mysqli_connect_error();
|
||||
|
@ -82,12 +85,13 @@ $row = mysqli_fetch_assoc($res);
|
|||
echo $row['_msg'];
|
||||
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
|
||||
|
||||
$res = $mysqli->query("SELECT 'choices to please everybody,' AS _msg FROM DUAL");
|
||||
$row = $res->fetch_assoc();
|
||||
echo $row['_msg'];
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -114,8 +118,9 @@ A world full of choices to please everybody.
|
|||
<title>Bad coding style</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
|
||||
|
||||
$res = mysqli_query($mysqli, "SELECT 'Possible but bad style.' AS _msg FROM DUAL");
|
||||
|
@ -124,6 +129,7 @@ if (!$res)
|
|||
|
||||
if ($row = $res->fetch_assoc())
|
||||
echo $row['_msg'];
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -168,15 +174,17 @@ Possible but bad style.
|
|||
<title>Special meaning of localhost</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("localhost", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
echo $mysqli->host_info . "\n";
|
||||
|
||||
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
echo $mysqli->host_info . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -354,14 +362,16 @@ mysqli.default_socket=/tmp/mysql.sock
|
|||
<title>Bad coding style</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
!$mysqli->query("CREATE TABLE test(id INT)") ||
|
||||
!$mysqli->query("INSERT INTO test(id) VALUES (1)"))
|
||||
echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -389,8 +399,9 @@ if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
|||
<title>Navigation through buffered results</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -411,6 +422,7 @@ echo "Result set order...\n";
|
|||
$res->data_seek(0);
|
||||
while ($row = $res->fetch_assoc())
|
||||
echo " id = " . $row['id'] . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -442,12 +454,14 @@ Result set order...
|
|||
<title>Navigation through buffered results</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli->real_query("SELECT id FROM test ORDER BY id ASC");
|
||||
$res = $mysqli->use_result();
|
||||
|
||||
echo "Result set order...\n";
|
||||
while ($row = $res->fetch_assoc())
|
||||
echo " id = " . $row['id'] . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -472,8 +486,9 @@ while ($row = $res->fetch_assoc())
|
|||
<title>Text protocol returns strings by default</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -486,6 +501,7 @@ $row = $res->fetch_assoc();
|
|||
|
||||
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
|
||||
printf("label = %s (%s)\n", $row['label'], gettype($row['label']));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -510,10 +526,11 @@ label = a (string)
|
|||
<title>Native data types with mysqlnd and conneciton option</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = mysqli_init();
|
||||
$mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
|
||||
$mysqli->real_connect("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -526,6 +543,7 @@ $row = $res->fetch_assoc();
|
|||
|
||||
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
|
||||
printf("label = %s (%s)\n", $row['label'], gettype($row['label']));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -579,8 +597,9 @@ label = a (string)
|
|||
<title>First stage: prepare</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
/* Non-prepared statement */
|
||||
|
@ -591,6 +610,7 @@ if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
|||
/* Prepared statement, stage 1: prepare */
|
||||
if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)")))
|
||||
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -606,6 +626,7 @@ if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)")))
|
|||
<title>Second stage: bind and execute</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* Prepared statement, stage 2: bind and execute */
|
||||
$id = 1;
|
||||
if (!$stmt->bind_param("i", $id))
|
||||
|
@ -613,6 +634,7 @@ if (!$stmt->bind_param("i", $id))
|
|||
|
||||
if (!$stmt->execute())
|
||||
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -631,8 +653,9 @@ if (!$stmt->execute())
|
|||
<title>INSERT prepared once, executed multiple times</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
/* Non-prepared statement */
|
||||
|
@ -663,6 +686,7 @@ $stmt->close();
|
|||
/* Non-prepared statement */
|
||||
$res = $mysqli->query("SELECT id FROM test");
|
||||
var_dump($res->fetch_all());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -717,8 +741,10 @@ array(4) {
|
|||
<title>Less round trips using multi-INSERT SQL</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
if (!$mysqli->query("INSERT INTO test(id) VALUES (1), (2), (3), (4)"))
|
||||
echo "Multi-INSERT failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -741,8 +767,9 @@ if (!$mysqli->query("INSERT INTO test(id) VALUES (1), (2), (3), (4)"))
|
|||
<title>Native datatypes</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -757,6 +784,7 @@ $row = $res->fetch_assoc();
|
|||
|
||||
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
|
||||
printf("label = %s (%s)\n", $row['label'], gettype($row['label']));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -790,8 +818,9 @@ label = a (string)
|
|||
<title>Output variable binding</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -814,6 +843,7 @@ while ($stmt->fetch())
|
|||
printf("id = %s (%s), label = %s (%s)\n",
|
||||
$out_id, gettype($out_id),
|
||||
$out_label, gettype($out_label));
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -850,8 +880,9 @@ id = 1 (integer), label = a (string)
|
|||
<title>Using mysqli_result to fetch results</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -869,6 +900,7 @@ if (!($res = $stmt->get_result()))
|
|||
echo "Getting result set failed: (" . $stmt->errno . ") " . $stmt->error;
|
||||
|
||||
var_dump($res->fetch_all());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -896,8 +928,9 @@ array(1) {
|
|||
<title>Buffered result set for flexible read out</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -919,6 +952,7 @@ for ($row_no = ($res->num_rows - 1); $row_no >= 0; $row_no--) {
|
|||
var_dump($res->fetch_assoc());
|
||||
}
|
||||
$res->close();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1097,8 +1131,9 @@ array(2) {
|
|||
<title>Calling a stored procedure</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -1116,6 +1151,7 @@ if (!($res = $mysqli->query("SELECT id FROM test")))
|
|||
echo "SELECT failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
|
||||
var_dump($res->fetch_assoc());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1141,8 +1177,9 @@ array(1) {
|
|||
<title>Using session variables</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP PROCEDURE IF EXISTS p") ||
|
||||
|
@ -1159,6 +1196,7 @@ if (!($res = $mysqli->query("SELECT @msg as _p_out")))
|
|||
|
||||
$row = $res->fetch_assoc();
|
||||
echo $row['_p_out'];
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1199,8 +1237,9 @@ Hi!
|
|||
<title>Fetching results from stored procedures</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -1225,6 +1264,7 @@ do {
|
|||
echo "Store failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
}
|
||||
} while ($mysqli->more_results() && $mysqli->next_result());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1285,8 +1325,9 @@ array(3) {
|
|||
<title>Stored Procedures and Prepared Statements</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -1315,6 +1356,7 @@ do {
|
|||
echo "Store failed: (" . $stmt->errno . ") " . $stmt->error;
|
||||
}
|
||||
} while ($stmt->more_results() && $stmt->next_result());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1327,6 +1369,7 @@ do {
|
|||
<title>Stored Procedures and Prepared Statements using bind API</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
if (!($stmt = $mysqli->prepare("CALL p()")))
|
||||
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
|
||||
|
@ -1342,6 +1385,7 @@ do {
|
|||
while ($stmt->fetch())
|
||||
echo "id = $id_out\n";
|
||||
} while ($stmt->more_results() && $stmt->next_result());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1380,8 +1424,9 @@ do {
|
|||
<title>Multiple Statements</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
|
||||
|
@ -1401,6 +1446,7 @@ do {
|
|||
$res->free();
|
||||
}
|
||||
} while ($mysqli->more_results() && $mysqli->next_result());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1443,10 +1489,12 @@ array(1) {
|
|||
<title>SQL ijnection</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
$res = $mysqli->query("SELECT 1; DROP TABLE mysql.user");
|
||||
if (!$res)
|
||||
echo "Error executing query: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1492,8 +1540,9 @@ Error executing query: (1064) You have an error in your SQL syntax; check the ma
|
|||
<title>Setting auto commit mode with SQL and through the API</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
/* Recommended: using API to control transactional settings */
|
||||
|
@ -1502,6 +1551,7 @@ $mysqli->autocommit(false);
|
|||
/* Won't be monitored and recognized by the replication and the load balancing plugin */
|
||||
if (!$mysqli->query('SET AUTOCOMMIT = 0'))
|
||||
echo "Query failed: (" . $mysqli->errno . ") " . $mysqli->error;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1518,6 +1568,7 @@ if (!$mysqli->query('SET AUTOCOMMIT = 0'))
|
|||
<title>Commit and rollback</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
$mysqli->autocommit(false);
|
||||
|
||||
|
@ -1526,6 +1577,7 @@ $mysqli->rollback();
|
|||
|
||||
$mysqli->query("INSERT INTO test(id) VALUES (2)");
|
||||
$mysqli->commit();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -1563,12 +1615,14 @@ $mysqli->commit();
|
|||
<title>Accessing result set meta data</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$mysqli = new mysqli("example.com", "user", "password", "database");
|
||||
if ($mysqli->connect_errno))
|
||||
if ($mysqli->connect_errno)
|
||||
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
|
||||
|
||||
$res = $mysqli->query("SELECT 1 AS _one, 'Hello' AS _two FROM DUAL");
|
||||
var_dump($res->fetch_fields());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
|
@ -1651,10 +1705,12 @@ array(2) {
|
|||
<title>Prepared statements metadata</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$stmt = $mysqli->prepare("SELECT 1 AS _one, 'Hello' AS _two FROM DUAL");
|
||||
$stmt->execute();
|
||||
$res = $stmt->result_metadata();
|
||||
var_dump($res->fetch_fields());
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue