当前位置:Gxlcms > PHP教程 > 下面有两段代码为什么执行结果不一样,帮解释,多谢

下面有两段代码为什么执行结果不一样,帮解释,多谢

时间:2021-07-01 10:21:17 帮助过:30人阅读

下面有两段代码为什么执行结果不一样,帮解释,谢谢
$userName="root";
$userPwd="1234";
$dbName="test";
$serverName="localhost";
//连接数据库
$conn=mysql_connect("localhost","root","1234");
//选择数据库
$select=mysql_select_db("test",$conn);
if($select){
echo"数据库连接成功";
}
?>
和下面的代码执行结果不同,请分析下 $userName="root";
$userPwd="1234";
$dbName="test";
$serverName="localhost";

//连接数据库
$this->conn=mysql_connect($this->serverName,$this->userName,$this->userPwd);
//选择数据库
$this->my_db=mysql_select_db($this->dbName,$this->conn);
if($this->my_db){
echo"数据库连接成功";
}
?>

分享到: 更多


------解决方案--------------------
在 ?> 前加入
}
new login;

人气教程排行