1
我是OOP的新手,並且在創建數據庫連接時遇到問題,可能是什麼問題?奇怪的是我沒有得到任何錯誤,但我不能做任何MYSQL插入或從數據庫中選擇,因爲連接尚未取得使用對象進行數據庫連接
//include the file that contains variables necessary for database connection
require_once 'configurations.php';
//This is the class that will be used for the MySQL Database transactions
class MySQLDatabase
{
private $database_connection;
//constructor class
function __construct()
{
$this->open_connection();
}
public function open_connection()
{
$this->database_connection = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
if (!$this->database_connection)
{
//if the connection fails, return the following message and indicate the error
die("Could not connect to the MYSQL Database due to: " . mysql_error());
}
else
{
//if the connection is made to MYSQL database, then select the database being used
$database_selection = mysql_select_db(DATABASE_NAME, $this->database_connection);
//if the database to be used cannot be selected, return this error
if (!$database_selection)
{
die ("Could not select the database due to: " . mysql_error());
}
}
}//end of function open database
}//end of class MySQLDatabase
$database_transactions = new MySQLDatabase();
您是否收到任何錯誤訊息?你在試圖告訴你它不工作? – 2011-01-27 06:13:29