mysql_connect
本扩展自 PHP 5.5.0起已废弃,并在将来会被移除。应使用MySQLi或PDO_MySQL扩展来替换之
下面是代码
$link=mysql_connect(cd_sqlservername, cd_sqluserid, cd_sqlpwd) or show_msg('数据库连接异常,无法执行!', 999);
mysql_select_db(cd_sqldbname, $link) or show_msg('数据库连接异常,无法执行!', 999);
mysql_query("SET NAMES utf8",$link);
$table=file_get_contents("table.sql");$table=ReplaceStr($table,"cmsdj_",cd_tablename);
$tablearr=explode(";",$table);
$data=file_get_contents("data.sql");
$data=ReplaceStr($data,"cmsdj_",cd_tablename);
$dataarr=explode("--cmsdj--",$data);
$sqlarr=explode("结构*/",$table);
$str="
正在安装数据...
{replace}";
for($i=0;$i
mysql_query($tablearr[$i]);
}
for($i=0;$i mysql_query($dataarr[$i]);
}
for($i=0;$i $strsql=explode("/*数据",$sqlarr[$i]);
$str.=$strsql[1];
}
$str=ReplaceStr($str,"表 `","建立数据表 ");
$str=ReplaceStr($str,"` 的"," ... 成功
{replace}");
$str=$str."安装附加数据 ... 成功
{replace}";
//连接并选择数据库 $mysqli = new mysqli("localhost", "my_user", "my_password", "my_db_name"); //如果连接失败 if ($mysqli->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } $sql = "SELECt * FROM admin where `username` = '$username'"; //query 后面都差不多 $result = $mysqli -> query($sql); $uname = is_array($row = $result -> fetch_assoc()); $pwd = $uname ? $password == $row["password"] : FALSE; if($pwd){ $_SESSION["id"] = $row["id"]; $_SESSION["permit"] = $row["password"]; echo "OK!"; }else{ echo "Fail!"; session_destroy(); } $mysqli->close();
//连接并选择数据库
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db_name");
//如果连接失败
if ($mysqli->connect_errno) {
printf("connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql = "select * from admin where `username` = '$username'";
//query 后面都差不多
$result = $mysqli -> query($sql);
$uname = is_array($row = $result -> fetch_assoc());
$pwd = $uname ? $password == $row["password"] : false;
if($pwd){
$_session["id"] = $row["id"];
$_session["permit"] = $row["password"];
echo "ok!";
}else{
echo "fail!";
session_destroy();
}
$mysqli->close();