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=''");
}
}