好的,所以我将所有的sql语句转换为预处理语句,我似乎无法弄清楚为什么这不会返回任何数据:
public function get_all_movies(){
if($result = $this->link->prepare("SELECT id,type,name,description,cover,movie FROM movies")){
$result->execute();
$result->store_result();
$result->bind_result($id,$type,$name,$description,$cover,$movie);
if($result->num_rows !=0){
$results = array();
$result->fetch();
$results['id'] = $id;
$results['type'] = $type;
$results['name'] = $name;
$results['description'] = $description;
$results['cover'] = $cover;
$results['movie'] = $movie;
return $results;
}else {
return array("error"=>"No-media-found");
}
$result->close();
}
}
转换自:
public function getAllMovies(){
if($result = $this->link->query("SELECT * FROM movies")){
if($result->num_rows != 0){
$movies = array();
while($movie = $result->fetch_assoc()){
array_push($movies,$movie);
}
return $movies;
}else{
return array("error"=>"No media found");
}
}
}
有任何建议吗?
答案 0 :(得分:0)
要选择所有字段,请使用*
符号:
$this->link->prepare("SELECT * FROM movies"))
或使用表格的前缀:
$this->link->prepare("SELECT m.* FROM movies AS m"))