mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
adding some php.ini related stuff in partintro.
cleaning up the examples. some ws fixes. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@64490 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
86b80338f8
commit
95b7c9cb92
1 changed files with 120 additions and 60 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.77 $ -->
|
||||
<!-- $Revision: 1.78 $ -->
|
||||
<reference id="ref.mysql">
|
||||
<title>MySQL Functions</title>
|
||||
<titleabbrev>MySQL</titleabbrev>
|
||||
|
@ -26,6 +26,60 @@
|
|||
Documentation for MySQL can be found at <ulink
|
||||
url="&url.mysql.docs;">&url.mysql.docs;</ulink>.
|
||||
</simpara>
|
||||
<para>
|
||||
The behaviour of the MySQL functions is affected by settings in the global
|
||||
<link linkend="configuration">configuration</link> file.
|
||||
<table>
|
||||
<title><link linkend="ini.sect.mysql">MySQL Configuration </link> Options</title>
|
||||
<tgroup cols="3">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Name</entry>
|
||||
<entry>Default</entry>
|
||||
<entry>Changeable</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>mysql.allow_persistent</entry>
|
||||
<entry>"On"</entry>
|
||||
<entry>PHP_INI_SYSTEM</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.max_persistent</entry>
|
||||
<entry>"-1"</entry>
|
||||
<entry>PHP_INI_SYSTEM</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.max_links</entry>
|
||||
<entry>"-1"</entry>
|
||||
<entry>PHP_INI_SYSTEM</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.default_port</entry>
|
||||
<entry>NULL</entry>
|
||||
<entry>PHP_INI_ALL</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.default_socket</entry>
|
||||
<entry>NULL</entry>
|
||||
<entry>PHP_INI_ALL</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.default_host</entry>
|
||||
<entry>NULL</entry>
|
||||
<entry>PHP_INI_ALL</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>mysql.default_user</entry>
|
||||
<entry>NULL</entry>
|
||||
<entry>PHP_INI_ALL</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
For further details and definition of the PHP_INI_* constants see <function>ini_set</function>.
|
||||
</para>
|
||||
<para>
|
||||
This simple example shows how to connect, execute a query, print
|
||||
resulting rows and disconnect from a MySQL database.
|
||||
|
@ -217,10 +271,10 @@ mysql_close($link);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect ("kraemer", "marliesle", "secret")
|
||||
or die ("Could not connect");
|
||||
$link = mysql_connect("kraemer", "marliesle", "secret")
|
||||
or exit("Could not connect");
|
||||
print ("Connected successfully");
|
||||
mysql_close ($link);
|
||||
mysql_close($link);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -304,10 +358,10 @@ mysql_close($link);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_connect ("localhost", "username", "secret")
|
||||
or die ("Could not connect");
|
||||
$link = mysql_connect("localhost", "username", "secret")
|
||||
or die("Could not connect");
|
||||
print ("Connected successfully");
|
||||
mysql_close ($link);
|
||||
mysql_close($link);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -350,9 +404,9 @@ mysql_close($link);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$link = mysql_pconnect ("kron", "jutta", "geheim")
|
||||
or die ("Could not connect");
|
||||
if (mysql_create_db ("my_db")) {
|
||||
$link = mysql_pconnect("kron", "jutta", "geheim")
|
||||
or exit("Could not connect");
|
||||
if (mysql_create_db("my_db")) {
|
||||
print ("Database created successfully\n");
|
||||
} else {
|
||||
printf ("Error creating database: %s\n", mysql_error ());
|
||||
|
@ -386,7 +440,7 @@ mysql_close($link);
|
|||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
&return.success;
|
||||
&return.success;
|
||||
</para>
|
||||
<para>
|
||||
<function>mysql_data_seek</function> moves the internal row
|
||||
|
@ -402,31 +456,31 @@ mysql_close($link);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
&<?php
|
||||
$link = mysql_pconnect ("kron", "jutta", "geheim")
|
||||
or die ("Could not connect");
|
||||
$link = mysql_pconnect("kron", "jutta", "geheim")
|
||||
or die("Could not connect");
|
||||
|
||||
mysql_select_db ("samp_db")
|
||||
or die ("Could not select database");
|
||||
mysql_select_db("samp_db")
|
||||
or exit("Could not select database");
|
||||
|
||||
$query = "SELECT last_name, first_name FROM friends";
|
||||
$result = mysql_query ($query)
|
||||
or die ("Query failed");
|
||||
$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)) {
|
||||
for ($i = mysql_num_rows($result) - 1; $i >=0; $i--) {
|
||||
if (!mysql_data_seek($result, $i)) {
|
||||
echo "Cannot seek to row $i\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!($row = mysql_fetch_object ($result)))
|
||||
if(!($row = mysql_fetch_object($result)))
|
||||
continue;
|
||||
|
||||
echo "$row->last_name $row->first_name<br />\n";
|
||||
}
|
||||
|
||||
mysql_free_result ($result);
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -786,15 +840,16 @@ select tone.field as foo ttwo.field as bar from tone, ttwo
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password);
|
||||
$result = mysql_db_query ("database","select user_id, fullname from table");
|
||||
while ($row = mysql_fetch_array ($result)) {
|
||||
mysql_connect($host, $user, $password);
|
||||
mysql_select_db("database");
|
||||
$result = mysql_query("select user_id, fullname from table");
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
echo "user_id: ".$row["user_id"]."<br>\n";
|
||||
echo "user_id: ".$row[0]."<br>\n";
|
||||
echo "fullname: ".$row["fullname"]."<br>\n";
|
||||
echo "fullname: ".$row[1]."<br>\n";
|
||||
}
|
||||
mysql_free_result ($result);
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -854,13 +909,15 @@ mysql_free_result ($result);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password);
|
||||
$result = mysql_db_query ("database","select * from table");
|
||||
while ($row = mysql_fetch_assoc ($result)) {
|
||||
mysql_connect($host, $user, $password);
|
||||
mysql_select_db($database);
|
||||
$query = "select * from table";
|
||||
$result = mysql_query($query);
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
echo $row["user_id"];
|
||||
echo $row["fullname"];
|
||||
}
|
||||
mysql_free_result ($result);
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -967,15 +1024,16 @@ mysql_free_result ($result);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password)
|
||||
mysql_connect('localhost:3306', $user, $password)
|
||||
or die ("Could not connect");
|
||||
$result = mysql_db_query ("database", "select * from table")
|
||||
or die ("Query failed");
|
||||
mysql_select_db("database");
|
||||
$result = mysql_query("select * from table")
|
||||
or die("Query failed");
|
||||
# get column metadata
|
||||
$i = 0;
|
||||
while ($i < mysql_num_fields ($result)) {
|
||||
while ($i < mysql_num_fields($result)) {
|
||||
echo "Information for column $i:<BR>\n";
|
||||
$meta = mysql_fetch_field ($result);
|
||||
$meta = mysql_fetch_field($result);
|
||||
if (!$meta) {
|
||||
echo "No information available<BR>\n";
|
||||
}
|
||||
|
@ -995,7 +1053,7 @@ zerofill: $meta->zerofill
|
|||
</PRE>";
|
||||
$i++;
|
||||
}
|
||||
mysql_free_result ($result);
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -1086,13 +1144,14 @@ mysql_free_result ($result);
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password);
|
||||
$result = mysql_db_query ("database", "select * from table");
|
||||
while ($row = mysql_fetch_object ($result)) {
|
||||
mysql_connect("hostname", "user", $password");
|
||||
mysql_select_db($db);
|
||||
$result = mysql_query("select * from table");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo $row->user_id;
|
||||
echo $row->fullname;
|
||||
}
|
||||
mysql_free_result ($result);
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -1217,8 +1276,10 @@ mysql_free_result ($result);
|
|||
// user_id
|
||||
// username
|
||||
// password.
|
||||
|
||||
$res = mysql_db_query("users", "select * from users", $link);
|
||||
$link = mysql_connect('localhost', $user, "secret");
|
||||
mysql_select_db($dbname, $link)
|
||||
or die("Could not set $dbname");
|
||||
$res = mysql_query("select * from users", $link);
|
||||
|
||||
echo mysql_field_name($res, 0) . "\n";
|
||||
echo mysql_field_name($res, 2);
|
||||
|
@ -1353,20 +1414,20 @@ password
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
mysql_connect ("localhost:3306");
|
||||
mysql_select_db ("wisconsin");
|
||||
$result = mysql_query ("SELECT * FROM onek");
|
||||
$fields = mysql_num_fields ($result);
|
||||
$rows = mysql_num_rows ($result);
|
||||
mysql_connect("localhost:3306");
|
||||
mysql_select_db("wisconsin");
|
||||
$result = mysql_query("SELECT * FROM onek");
|
||||
$fields = mysql_num_fields($result);
|
||||
$rows = mysql_num_rows($result);
|
||||
$i = 0;
|
||||
$table = mysql_field_table ($result, $i);
|
||||
$table = mysql_field_table($result, $i);
|
||||
echo "Your '".$table."' table has ".$fields." fields and ".$rows." records <BR>";
|
||||
echo "The table has the following fields <BR>";
|
||||
while ($i < $fields) {
|
||||
$type = mysql_field_type ($result, $i);
|
||||
$name = mysql_field_name ($result, $i);
|
||||
$len = mysql_field_len ($result, $i);
|
||||
$flags = mysql_field_flags ($result, $i);
|
||||
$type = mysql_field_type($result, $i);
|
||||
$name = mysql_field_name($result, $i);
|
||||
$len = mysql_field_len($result, $i);
|
||||
$flags = mysql_field_flags($result, $i);
|
||||
echo $type." ".$name." ".$len." ".$flags."<BR>";
|
||||
$i++;
|
||||
}
|
||||
|
@ -1864,8 +1925,8 @@ echo "$num_rows Rows\n";
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<php
|
||||
$result = mysql_query ("SELECT * WHERE 1=1")
|
||||
or die ("Invalid query");
|
||||
$result = mysql_query("SELECT * WHERE 1=1")
|
||||
or die("Invalid query");
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -1881,8 +1942,8 @@ $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");
|
||||
$result = mysql_query("SELECT my_col FROM my_tbl")
|
||||
or exit ("Invalid query");
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@ -1914,7 +1975,6 @@ $result = mysql_query ("SELECT my_col FROM my_tbl")
|
|||
<para>
|
||||
See also: <function>mysql_num_rows</function>
|
||||
<function>mysql_affected_rows</function>,
|
||||
<function>mysql_db_query</function>,
|
||||
<function>mysql_unbuffered_query</function>,
|
||||
<function>mysql_free_result</function>,
|
||||
<function>mysql_fetch_array</function>,
|
||||
|
@ -2094,11 +2154,11 @@ $result = mysql_query ("SELECT my_col FROM my_tbl")
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect ("localhost:3306");
|
||||
$result = mysql_list_tables ("wisconsin");
|
||||
mysql_connect("host");
|
||||
$result = mysql_list_tables("wisconsin");
|
||||
$i = 0;
|
||||
while ($i < mysql_num_rows ($result)) {
|
||||
$tb_names[$i] = mysql_tablename ($result, $i);
|
||||
while ($i < mysql_num_rows($result)) {
|
||||
$tb_names[$i] = mysql_tablename($result, $i);
|
||||
echo $tb_names[$i] . "<BR>";
|
||||
$i++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue