<?php
//MySQL连接数据库
function db_connmysql($dbpassword,$dbdatabase,$dbhost='localhost',$dbname='root',$dbcharset='UTF8'){
$link = mysql_connect($dbhost, $dbname, $dbpassword) or die(mysql_error());
$dbVersion = mysql_get_server_info($link);
//设置字符集
mysql_set_charset($dbcharset,$link);
//mysql_query("SET NAMES gb2312", $link);此方式不推荐;
//设置 sql_model
if($dbVersion >'5.0.1'){
mysql_query("SET sql_mode=''",$link);
mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $link);// 防止宽字节注入
}
//选择数据库
mysql_select_db($dbdatabase, $link);
//mysql_close($link);
}
//db_connmysql('password','test');
…
近期评论