我要使用以下代码:
class ClsCreateElements{
//protected $mConnPer;
public static $mConnMy;
public function __construct(){
//echo("CLSCreateElements");
//$this->mConnPer = odbc_connect("LDVS","","") or die ("LDVS-Verbindung fehlegschagen");
self::$mConnMY = mysqli_connect("localhost","root","","lafuwa") or die ("MYSQL-Verbindung fehlgeschagen");
}
}
运行代码时,出现以下错误消息:
Uncaught Error: Access to undeclared static property: ClsCreateElements::$mConnMY in C:\xampp\htdocs\LDVS\php\classes\clsCreateElements.php:10
Stack trace:
#0 C:\xampp\htdocs\LDVS\php\ajax\newCustomer.php(6): ClsCreateElements->__construct()
#1 {main}
thrown in <b>C:\xampp\htdocs\LDVS\php\classes\clsCreateElements.php</b> on line <b>10</b><br />
出什么问题了?
答案 0 :(得分:1)
您有错字。 $mConnMY
应该是$mConnMy
。 PHP中的静态变量区分大小写。
您的声明:
public static $mConnMy;
您的访问者:
self::$mConnMY = ...
改为使用self::$mConnMy = ...
。