more examples for connecting with different syntax, link to client flags table, link to ini-setting

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@197436 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Friedhelm Betz 2005-10-03 10:37:09 +00:00
parent 2524ad6832
commit 2eabce8ccd

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.16 $ -->
<!-- $Revision: 1.17 $ -->
<refentry id="function.mysql-connect">
<refnamediv>
<refname>mysql_connect</refname>
@ -80,6 +80,7 @@
<constant>MYSQL_CLIENT_COMPRESS</constant>,
<constant>MYSQL_CLIENT_IGNORE_SPACE</constant> or
<constant>MYSQL_CLIENT_INTERACTIVE</constant>.
Read the section about <xref linkend="mysql.client-flags" /> for further information.
</para>
</listitem>
</varlistentry>
@ -152,6 +153,61 @@ if (!$link) {
echo 'Connected successfully';
mysql_close($link);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>mysql_connect</function>example using <literal>hostname:port</literal> syntax</title>
<programlisting role="php">
<![CDATA[
<?php
// we connect to example.com and port 3307
$link = mysql_connect('example.com:3307', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
// we connect to localhost at port 3307
$link = mysql_connect('127.0.0.1:3307', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>mysql_connect</function>example using ":/path/to/socket" syntax</title>
<programlisting role="php">
<![CDATA[
<?php
// we connect to localhost and socket e.g. /tmp/mysql.sock
//variant 1: ommit localhost
$link = mysql_connect('/tmp/mysql', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
// variant 2: with localhost
$link = mysql_connect('localhost:/tmp/mysql.sock', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
]]>
</programlisting>
</example>
@ -168,7 +224,7 @@ mysql_close($link);
Windows). If you want to use TCP/IP, use &quot;127.0.0.1&quot;
instead of &quot;localhost&quot;. If the MySQL client library tries to
connect to the wrong local socket, you should set the correct path as
mysql.default_host in your PHP configuration and leave the server field
<xref linkend=" ini.mysql.default-host" /> in your PHP configuration and leave the server field
blank.
</para>
</note>