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');

posted on 2017-04-30 19:52  风生水生  阅读(137)  评论(0编辑  收藏  举报

导航