在我的Android應用程序中。我試圖驗證用戶,因爲我寫了一個PHP腳本來建立連接到數據庫,但不幸的是我得到以下錯誤 -未定義變量:con在C: wamp www android_connect db_connect.php在線
「Undefined variable:con in C:\ wamp \ WWW \ android_connect \ db_connect.php上線「
爲了解決這個錯誤我已經宣佈」$ CON「爲全局變量,但仍然得到同樣的錯誤 -
我db_connect.php代碼---
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT
{
private $con;
// constructor
function __construct()
{
// connecting to database
$this->connect();
}
// destructor
function __destruct()
{
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect()
{
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
// Selecing database
$db = mysqli_select_db($con, DB_DATABASE);
// returing connection cursor
return $con;
}
/*
* Function to close db connection
*/
function close()
{
// closing db connection
mysqli_close($con);
}
}
?>
請幫助。謝謝..!
您需要參考'$這個 - > con' –