2
有我sqli
請求沒有結果..像空的數據。我敢肯定,我的數據庫中有多少數據PHP的價值沒有結果的mysqli stmt是
這裏是我的代碼,糾正我,如果我上了錯誤我的代碼
<?php
// include db handler
class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'include/DB_Connect.php';
// connecting to database
$db = new Db_Connect();
$this->conn = $db->connect();
}
// destructor
function __destruct() {
}
function getSliderList(){
$stmt = $this->conn->prepare("SELECT cPID, image FROM sliderImage");
$stmt->execute();
if ($stmt->num_rows > 0) {
$result = $stmt->get_result()->fetch_assoc();
$response[] = $result;
$stmt->close();
echo json_encode($response);
return true;
} else {
// user not found
return false;
}
}
}
$x = new DB_Functions();
$user = $x->getSliderList();
$response = Array();
if($user){
$user;
return false;
} else {
$response['error'] = "Sorry an error occured. Our Problem, not you.";
return true;
}
?>
我的數據庫請求連接
<?php
class DB_Connect {
private $conn;
// Connecting to database
public function connect() {
require_once 'include/Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
// return database handler
return $this->conn;
}
}
?>
和config.php
文件
<?php
/**
* Database config variables
*/
define("DB_HOST", "localhost");
define("DB_USER", "bxxx");
define("DB_PASSWORD", "xxxx");
define("DB_DATABASE", "xxxx");
?>
我想結果放入數組..和使用json_encode
在我的應用程序使用它發送此數據...
你有錯誤報告嗎? –
不,沒有什麼結果,即使是一個錯誤... –
爲什麼你準備不需要輸入的語句 –