我正在尝试使用 OO PHP,但是当我尝试代码时,我收到错误消息,指出 dbhost、dbuser、dbpass 和 dbname 未定义。Netbeans 还给我一个警告,说它们可能未初始化。删除 static 关键字会给我一个错误,说 'Unexpected "$dbhost" '。有谁知道我做错了什么?
<?php
class DatabaseManager {
private static $dbhost = 'localhost';
private static $dbuser = 'root';
private static $dbpass = '';
private static $dbname = 'app_db';
public static function getConnection(){
$dbconn;
try {
$dbconn = new PDO('mysql:host='.$dbhost,'dbname='.$dbname,
$dbuser, $dbpass);
} catch (PDOException $e) {
echo "Could not connect to database";
echo $e;
exit;
}
return $dbconn;
}
}
?>