php 连接mysql 代码 端口号是3307!

来源:百度知道 编辑:UC知道 时间:2024/06/21 15:08:45
求一段php连接mysql的代码
服务器 :localhost
端口:3307
用户名:root
密码:110
数据库:test
请尽量详细的说明下,我刚接触PHP,不大懂!学习下!谢谢了!:)
mysql安装的不是默然的3306 端口,是装在了3307上,所以连接需要端口才行! 请问带上端口的话,连接语句该怎么写啊?!写localhost 肯定不行了!localhost:3307 连接也是失败!

php连接mysql脚本如下:

$host = 'mysql服务器ip或域名';
$port = 3307;//mysql端口号,默认为3306,此处为3307
$user = 'mysql用户名';
$pwd = '密码';
$link = @mysql_connect("{$host}:{$port}", $user, $pwd, true);
if(!$link) {
    die('Database Connect Error:'.mysql_error());
}

mysql_connect函数介绍:

mysql_connect — 打开一个到 MySQL 服务器的连接

resource mysql_connect    ([ string $server   [, string $username   [, string $password   [, bool $new_link   [, int $client_flags  ]]]]] )

打开或重复使用一个到 MySQL 服务器的连接

server:MySQL 服务器。可以包括端口号,例如        "hostname:port",或者到本地套接字的路径,例如对于 localhost 的 ":/path/to/socket"。

username:用户名。

password:密码。

new_link(4.2.0添加):如果用同样的参数第二次调用mysql_connect(),将不会建立新连接,而将返回已经打开的连接标识。参数new_link