关于php6连接MySQL数据库,要注意这样一些事项。php6默认与MysqLnd连接,所以链接MySQL数据库时就要注意,将有tcp协议的地方改为socket通信协议,或者在连接数据库时,出现的localhost统统改为127.0.0.1,如此而已。
<?php
ob_start();
$username = $_POST['username'];
$passwords = $_POST['password'];
if($username==null||$passwords==null){//此处判断用户名和密码是否为空
header("127.0.0.1:a/index.html");//进行跳转
echo "请确定用户名和密码都已填写";
}else {
$sql="select * from userlist where username = '".$username."' and password = '".$passwords."'";//sql语句
}
class DataBase{
public $dbhost = "127.0.0.1";//以下四行代码为与数据库取得链接
public $dbuser = "root";
public $dbpass = "1933jld1945js";
public $dbname = "karl";
function conn(){//判断是否成功连接数据库
$dbconn = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die("database error!".mysql_error());
mysql_select_db($this->dbname) or die("can not connect database:".mysql_error());
return $dbconn;
}
function indb($in_sql){//执行sql语句
$result_indb = mysql_query($in_sql) or die("can not run the sql language:".mysql_error());
return $result_indb;
}
}
$db = new DataBase();
$db->conn();
$k= $db->indb($sql);
//if(mysql_fetch_row($k)){//判断用户是否登陆成功
//$kiss=mysql_fetch_array(mysql_query($sql));
//$sss=$kiss["username"];
//$ss="location:frontvideo.php?kk=".$sss;//设置连接
// header($ss);
//}else{
// header("location:music/musicbox.php");//进行跳转
//}
if(mysql_fetch_row($k)){
header("location:http://www.baidu.com");
exit;
}else{
header("location:a/index.html");
}
?>