mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
CS, minor bugs
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@151948 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
66834c02bb
commit
f46de98880
15 changed files with 120 additions and 79 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.13 $ -->
|
||||
<!-- $Revision: 1.14 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-affected-rows">
|
||||
<refnamediv>
|
||||
|
@ -57,16 +57,18 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
/* connect to database */
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
mysql_select_db("mydb");
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
mysql_select_db('mydb');
|
||||
|
||||
/* this should return the correct numbers of deleted records */
|
||||
mysql_query("DELETE FROM mytable WHERE id < 10");
|
||||
printf("Records deleted: %d\n", mysql_affected_rows());
|
||||
mysql_query('DELETE FROM mytable WHERE id < 10');
|
||||
printf('Records deleted: %d\n', mysql_affected_rows());
|
||||
|
||||
/* without a where clause in a delete statement, it should return 0 */
|
||||
mysql_query("DELETE FROM mytable");
|
||||
/* with a where clause that is never true, it should return 0 */
|
||||
mysql_query('DELETE FROM mytable WHERE 0');
|
||||
printf("Records deleted: %d\n", mysql_affected_rows());
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-close">
|
||||
<refnamediv>
|
||||
|
@ -41,9 +41,11 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
echo "Connected successfully";
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
echo 'Connected successfully';
|
||||
mysql_close($link);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- $Revision: 1.12 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-connect">
|
||||
<refnamediv>
|
||||
|
@ -95,9 +95,11 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
echo "Connected successfully";
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
echo 'Connected successfully';
|
||||
mysql_close($link);
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-create-db">
|
||||
<refnamediv>
|
||||
|
@ -29,13 +29,15 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
|
||||
if (mysql_create_db("my_db")) {
|
||||
if (mysql_create_db('my_db')) {
|
||||
echo "Database created successfully\n";
|
||||
} else {
|
||||
echo "Error creating database: " . mysql_error() . "\n";
|
||||
echo 'Error creating database: ' . mysql_error() . "\n";
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- $Revision: 1.11 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-data-seek">
|
||||
<refnamediv>
|
||||
|
@ -42,16 +42,19 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
|
||||
mysql_select_db("samp_db")
|
||||
or die("Could not select database: " . mysql_error());
|
||||
|
||||
$query = "SELECT last_name, first_name FROM friends";
|
||||
$result = mysql_query($query)
|
||||
or die("Query failed: " . mysql_error());
|
||||
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
$db_selected = mysql_select_db('sample_db');
|
||||
if (!$db_selected) {
|
||||
die('Could not select database: ' . mysql_error());
|
||||
}
|
||||
$query = 'SELECT last_name, first_name FROM friends';
|
||||
$result = mysql_query($query);
|
||||
if (!$result) {
|
||||
die('Query failed: ' . mysql_error());
|
||||
}
|
||||
/* fetch rows in reverse order */
|
||||
for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
|
||||
if (!mysql_data_seek($result, $i)) {
|
||||
|
@ -59,10 +62,11 @@ for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!($row = mysql_fetch_object($result)))
|
||||
if (!($row = mysql_fetch_assoc($result))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo "$row->last_name $row->first_name<br />\n";
|
||||
echo $row['last_name'] . ' ' . $row['first_name'] . "<br />\n";
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-fetch-field">
|
||||
<refnamediv>
|
||||
|
@ -98,11 +98,15 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect('localhost:3306', $user, $password)
|
||||
or die("Could not connect: " . mysql_error());
|
||||
mysql_select_db("database");
|
||||
$result = mysql_query("select * from table")
|
||||
or die("Query failed: " . mysql_error());
|
||||
$conn = mysql_connect('localhost:3306', 'user', 'password');
|
||||
if (!$conn) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
mysql_select_db('database');
|
||||
$result = mysql_query('select * from table');
|
||||
if (!$result) {
|
||||
die('Query failed: ' . mysql_error());
|
||||
}
|
||||
/* get column metadata */
|
||||
$i = 0;
|
||||
while ($i < mysql_num_fields($result)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-field-name">
|
||||
<refnamediv>
|
||||
|
@ -42,11 +42,16 @@
|
|||
* username
|
||||
* password.
|
||||
*/
|
||||
$link = mysql_connect('localhost', "mysql_user", "mysql_password");
|
||||
$dbname = "mydb";
|
||||
mysql_select_db($dbname, $link)
|
||||
or die("Could not set $dbname: " . mysql_error());
|
||||
$res = mysql_query("select * from users", $link);
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$db_selected) {
|
||||
die('Could not set $dbname: ' . mysql_error());
|
||||
}
|
||||
$dbname = 'mydb';
|
||||
$db_selected = mysql_select_db($dbname, $link);
|
||||
if (!$db_selected) {
|
||||
die('Could not set $dbname: ' . mysql_error());
|
||||
}
|
||||
$res = mysql_query('select * from users', $link);
|
||||
|
||||
echo mysql_field_name($res, 0) . "\n";
|
||||
echo mysql_field_name($res, 2);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.mysql-get-host-info">
|
||||
<refnamediv>
|
||||
|
@ -25,8 +25,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
printf("MySQL host info: %s\n", mysql_get_host_info());
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.mysql-get-proto-info">
|
||||
<refnamediv>
|
||||
|
@ -25,8 +25,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
printf("MySQL protocol version: %s\n", mysql_get_proto_info());
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.96 -->
|
||||
<refentry id="function.mysql-get-server-info">
|
||||
<refnamediv>
|
||||
|
@ -25,8 +25,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
printf("MySQL server version: %s\n", mysql_get_server_info());
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-insert-id">
|
||||
<refnamediv>
|
||||
|
@ -56,9 +56,11 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
mysql_select_db("mydb");
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
mysql_select_db('mydb');
|
||||
|
||||
mysql_query("INSERT INTO mytable (product) values ('kossu')");
|
||||
printf("Last inserted record has id %d\n", mysql_insert_id());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<!-- $Revision: 1.10 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.62 -->
|
||||
<refentry id="function.mysql-query">
|
||||
<refnamediv>
|
||||
|
@ -47,8 +47,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$result = mysql_query("SELECT * WHERE 1=1")
|
||||
or die("Invalid query: " . mysql_error());
|
||||
$result = mysql_query('SELECT * WHERE 1=1');
|
||||
if (!$result) {
|
||||
die('Invalid query: ' . mysql_error());
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -64,8 +66,10 @@ $result = mysql_query("SELECT * WHERE 1=1")
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$result = mysql_query("SELECT my_col FROM my_tbl")
|
||||
or die("Invalid query: " . mysql_error());
|
||||
$result = mysql_query('SELECT my_col FROM my_tbl');
|
||||
if (!$result) {
|
||||
die('Invalid query: ' . mysql_error());
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.100 -->
|
||||
<refentry id="function.mysql-real-escape-string">
|
||||
<refnamediv>
|
||||
|
@ -33,8 +33,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
$item = "Zak's and Derick's Laptop";
|
||||
$escaped_item = mysql_real_escape_string($item, $link);
|
||||
printf("Escaped string: %s\n", $escaped_item);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-result">
|
||||
<refnamediv>
|
||||
|
@ -43,12 +43,14 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
|
||||
or die("Could not connect: " . mysql_error());
|
||||
|
||||
$result = mysql_query("SELECT name FROM work.employee")
|
||||
or die("Could not query:" . mysql_error());
|
||||
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Could not connect: ' . mysql_error());
|
||||
}
|
||||
$result = mysql_query('SELECT name FROM work.employee');
|
||||
if (!$result) {
|
||||
die('Could not query:' . mysql_error());
|
||||
}
|
||||
echo mysql_result($result, 2); // outputs third employee's name
|
||||
|
||||
mysql_close($link);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.6 $ -->
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.mysql-select-db">
|
||||
<refnamediv>
|
||||
|
@ -37,12 +37,16 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password')
|
||||
or die('Not connected : ' . mysql_error());
|
||||
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
||||
if (!$link) {
|
||||
die('Not connected : ' . mysql_error());
|
||||
}
|
||||
|
||||
// make foo the current db
|
||||
mysql_select_db('foo', $link) or die ('Can\'t use foo : ' . mysql_error());
|
||||
|
||||
$db_selected = mysql_select_db('foo', $link);
|
||||
if (!$db_selected) {
|
||||
die ('Can\'t use foo : ' . mysql_error());
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
Loading…
Reference in a new issue