0
我搜索了所有的網頁,但我沒有找到任何解決方案,我的問題..我有使用準備語句來執行SQL查詢一類DB_Functions .. DB_Functions.php致命錯誤:調用一個非對象的成員函數prepare(),調用prepare語句的對象不爲空
<?php
class DB_Functions {
private $con;
//constructor
function __construct(){
require_once __DIR__ . "/db_connect.php";
//connecting to database
$db = new DB_CONNECT();
$this->con = $db->connect();
//var_dump($conn);
}
//destructor
function __destruct(){
}
//store new firm //testing
public function storeFirm($name, $email, $tel, $address, $city, $code){
var_dump($this->con);
$stmt = $this->con->prepare("INSERT INTO Charset (charset) VALUES (?)");
$stmt->bind_param("s", $name);
$stmt->execute();
$stmt->close();
}
}
?>
變量$這 - > CON返回資源(4)使用式(MySQL的鏈路)的var_dump的
db_connect.php
class DB_CONNECT{
function __construct(){
//import database connection variables
require_once __DIR__ . "/db_config.php";
}
/*
function to connect with database
*/
function connect(){
//connecting to mysql database
$conn = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die (mysql_error() . PHP_EOL);
//select database
$db = mysql_select_db(DB_DATABASE, $conn) or die (mysql_error() . PHP_EOL);
/*check connection*/
if (mysql_error()){
printf("Connect failed: %s\n", mysql_error());
exit();
}
else {
mysql_set_charset("utf8", $conn) or die (mysql_error() . PHP_EOL);
//$this->setCharacterSet($con);
//returning connection cursor
//var_dump($conn);
return $conn;
}
}
/*function to close db connection*/
function close(){
//closing db connection
mysql_close();
}
//set utf-8 character set
function setCharacterSet($con){
if (mysql_client_encoding($con) != "utf8"){
//mysql_set_charset("utf8");
printf("The current character set is : " . mysql_client_encoding($con) . "\n");
}
}
}
?>
任何人都可以告訴我罪魁禍首在我的代碼裏面嗎?