lovebet愛博代维 | Linux群集 | lovebet愛博维护 咨询电话:13146530122

mysql_connect 打开新链接问题

发布日期:2012-12-05 22
resource mysql_connect ([ string $server [, string $username [, string $password [, bool $new_link [, int $client_flags ]]]]] )
第4个参数可以给 true 用来在同一个连接上打开新的连接。一般也用不上。
mysql_query 第2个参数表示使用的 mysql_conn ID
以下是测试代码:
<?php
//conn 1
$local_conn = mysql_connect('localhost','root','1');
mysql_select_db('test',$local_conn);

//conn 2
$net_conn = mysql_connect('192.168.0.122','gonpo','123456');
mysql_select_db('gonpo',$net_conn);

//query 1
$res1 = mysql_query('show databases',$local_conn);
while ($row = mysql_fetch_array($res1))
{
    var_dump($row);
}
echo '-----------------------------<br>';
$res2 = mysql_query('show databases',$net_conn);
while ($row = mysql_fetch_array($res2))
{
    var_dump($row);
}


----------------------------------------------------

<?php
//conn 1
$local_conn = mysql_connect('localhost','root','1',true);
mysql_select_db('test',$local_conn);

//conn 2
$net_conn = mysql_connect('localhost','root','1',true);
mysql_select_db('mysql',$net_conn);

//query 1
$res1 = mysql_query('show tables',$local_conn);
while ($row = mysql_fetch_array($res1))
{
    var_dump($row);
}
echo '-----------------------------<br>';
$res2 = mysql_query('show tables',$net_conn);
while ($row = mysql_fetch_array($res2))
{
    var_dump($row);
}