mysqli_connect参数的写法以及如何设置特定端口

http://www.youkud.com/content.php?id=813

mysqli的函数声明:mysqli mysqli_connect ( [string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket]]]]]] )

所以应该把端口号写在数据库名的后面:

$result=new mysqli('localhost','root','123456789','book_sc', 3308);

而把端口号和主机名写在一起的是mysql(不是mysqli)里的写法:

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

完整的链接数据库方法封装

    function dbconn($dbhost,$dbport,$dbuser,$dbpw,$dbname){
        $this->conn = mysqli_connect($dbhost,$dbuser,$dbpw,$dbname,$dbport);
        if($this->conn==null || !$this->conn){
            $this->halt("Connect to MySQL failed:".mysqli_connect_error());
        }
        $serverinfo = mysqli_get_server_info($this->conn);
        if ($serverinfo > '4.1') {
            mysqli_query($this->conn, "SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary");
        }
        if ($serverinfo > '5.0') {
            mysqli_query($this->conn, "SET sql_mode=''");
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值