首页 > 代码库 > php5.5过渡--mysql连接

php5.5过渡--mysql连接

以前:

// $conn=mysql_connect("localhost","root","");
// $db=mysql_select_db("web_scoring_system",$conn)or die("数据库连接失败:".mysql_error());
// mysql_query("set names utf8");

新:

$link = mysqli_connect(
‘localhost‘, /* The host to connect to 连接MySQL地址 */
‘root‘, /* The user to connect as 连接MySQL用户名 */
‘‘, /* The password to use 连接MySQL密码 */
‘dbname‘); /* The default database to query 连接数据库名称*/

if (!$link) {
printf("Can‘t connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
mysqli_query($link,‘set names utf8‘);

php5.5过渡--mysql连接