這裏是my_sqli
數據庫連接使用PHP數據庫連接的兩個SELECT查詢
class FbChatMock {
// Holds the database connection
private $dbConnection;
private $_dbHost = 'localhost';
private $_dbUsername = 'root';
private $_dbPassword = '';
public $_databaseName = 'erp5_temp2';
public function __construct() {
$this->dbConnection = new mysqli($this->_dbHost, $this->_dbUsername,
$this->_dbPassword, $this->_databaseName);
if ($this->dbConnection->connect_error) {
die('Connection error.');
}
}
我得到的getchat
函數的兩個參數:
public function getchat($userId, $id){
$meesage = array();
$query = "SELECT u.user_id FROM `users` u where u.id='$id'";
$resultObj = $this->dbConnection->query($query);
$user = $resultObj->fetch_assoc())
$userid = $user;
}
我從查詢得到$userid
變量,在此查詢中使用它:
$query = "SELECT u.id,c.message,c.sent_on FROM `chat` c JOIN
`users` u ON c.user_id=u.user_id where u.id='$id' AND c.user_id='$userid'";
// Execute the query
$resultObj = $this->dbConnection->query($query);
// Fetch all the rows at once.
while ($rows = $resultObj->fetch_assoc()){
$meesage[] = $rows;
}
return $meesage;
問題是我的第一個sql查詢無法正常工作。我通過顯示來自echo的$userid
值來測試它。
我改變了這一行$ userid = $ user ['user_id']; echo($ userid); exit();但它沒有顯示回顯結果 –