mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added some examples to the MySQL docs.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@17151 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b0ef928342
commit
2a56b4f1b9
1 changed files with 75 additions and 0 deletions
|
@ -116,6 +116,18 @@
|
|||
<function>mysql_close</function> will not close persistent links
|
||||
generated by <function>mysql_pconnect</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title>MySQL close example</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
$link = mysql_connect ("kraemer", "marliesle", "secret") {
|
||||
or die ("Could not connect");
|
||||
}
|
||||
print ("Connected successfully");
|
||||
mysql_close ($link);
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also: <function>mysql_connect</function>, and
|
||||
<function>mysql_pconnect</function>.
|
||||
|
@ -186,6 +198,18 @@
|
|||
the script ends, unless it's closed earlier by explicitly calling
|
||||
<function>mysql_close</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title>MySQL connect example</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
$link = mysql_connect ("kraemer", "marliesle", "secret") {
|
||||
or die ("Could not connect");
|
||||
}
|
||||
print ("Connected successfully");
|
||||
mysql_close ($link);
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para> See also
|
||||
<function>mysql_pconnect</function>, and
|
||||
<function>mysql_close</function>.
|
||||
|
@ -214,6 +238,21 @@
|
|||
database on the server associated with the specified link
|
||||
identifier.
|
||||
</para>
|
||||
<example>
|
||||
<title>MySQL create database example</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
$link = mysql_pconnect ("kron", "jutta", "geheim") {
|
||||
or die ("Could not connect");
|
||||
}
|
||||
if (mysql_create_db ("my_db")) {
|
||||
print ("Database created successfully\n");
|
||||
} else {
|
||||
printf ("Error creating database: %s\n", mysql_error ());
|
||||
}
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also: <function>mysql_drop_db</function>. For downwards
|
||||
compatibility <function>mysql_createdb</function> can also be
|
||||
|
@ -246,6 +285,42 @@
|
|||
<para>
|
||||
<parameter>Row_number</parameter> starts at 0.
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>MySQL data seek example</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
$link = mysql_pconnect ("kron", "jutta", "geheim") {
|
||||
or die ("Could not connect");
|
||||
}
|
||||
|
||||
mysql_select_db ("samp_db") {
|
||||
or die ("Could not select database");
|
||||
}
|
||||
|
||||
$query = "SELECT last_name, first_name FROM friends";
|
||||
$result = mysql_query ($query) {
|
||||
or die ("Query failed");
|
||||
}
|
||||
|
||||
# fetch rows in reverse order
|
||||
|
||||
for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) {
|
||||
if (!mysql_data_seek ($result, $i)) {
|
||||
printf ("Cannot seek to row %d\n", $i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!($row = mysql_fetch_object ($result)))
|
||||
continue;
|
||||
|
||||
printf ("%s %s<BR>\n", $row->last_name, $row->first_name);
|
||||
}
|
||||
|
||||
mysql_free_result ($result);
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue