我正在尝试使用 PDO 创建一个 SQL 表。
这是add.php:
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
echo "Connexion success...";
$sq = DB_CONNECT::$con->query($table);
if ($sq) {
echo 'Table created...';
}
?>
这是连接类 db_connect.php:
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
return $this->connect();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database and selecting database
try {
$con = new PDO(DB_DSN, DB_USER, DB_PASSWORD);
} catch (Exception $e) {
die('Erreur : ' . $e->getMessage());
}
// returing connection cursor
return $con;
}
}
当我尝试查询数据库时,我收到以下错误消息:
连接成功...致命错误:访问未声明的静态属性:第 15 行 /public_html/toutain/add.php 中的 DB_CONNECT::$con