【发布时间】:2016-12-05 10:40:07
【问题描述】:
我的sqli 请求没有结果......就像空数据一样......我很确定我的数据库中有很多数据
这是我的代码,如果我的代码有错误,请纠正我
<?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 发送此数据以在我的应用程序中使用它......
【问题讨论】:
-
你有错误报告吗?
-
不,即使是错误也没有任何结果......
-
为什么要准备不接受输入的语句
-
什么是 conn 是 mysqli 对象吗?
-
DB_Connect.php 包含什么,从类 DB_Connect 连接的方法是什么,它返回什么?