![](/img/trans.png)
[英]Output an image with PHP and Codeigniter cause the browser to show only blank screen
[英]construct php not work show blank in my browser
我創建了一個 php 類文件,但是當它運行時它不起作用
class User {
public function __construct(){
$host_name='localhost';
$username='root';
$password='';
$database_name='php';
$conn=mysql_connect($host_name,$username,$password);
if(!$conn)
{
die('Database Not Connected!');
}
else{
echo 'Database connected';
}
}
}
但沒有使用類它運行
您需要使用new
關鍵字實例化該類。 請記住使用括號來調用類構造函數方法:
class User {
public function __construct(){
$host_name='localhost';
$username='root';
$password='';
$database_name='php';
$conn=mysql_connect($host_name,$username,$password);
if(!$conn)
{
die('Database Not Connected!');
}
else{
echo 'Database connected';
}
}
}
$myUser = new User();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.