Php OOP选择查询 [英] Php OOP select query
问题描述
我正在尝试学习OOP,我正在尝试创建一个类,它将从我选择的表和行中选择信息。 (尽我所能解释它很好,不确定我是否做得很好)
这是我在课堂上的代码:
I'm trying to learn OOP and i'm trying to create a class which will select me info from a table and a line that i choose. (trying my best to explain it good, not sure if i'm doing very well tho)
This is my code in the class:
class SelectQuery {
public function db_select($query_table, $query_extra) {
//$result = mysqli_query($conn, "SELECT * FROM `ideas` WHERE `Accepted` = 1 ORDER BY RAND() LIMIT 1");
//$query = 'SELECT * FROM '.$query_table.' '.$query_extra.'';
//$results = $this->con->query($query);
$this->con = mysqli_connect('localhost', 'root', '', 'forum');
$results = $this->con->prepare('SELECT * FROM '.$query_table.' '.$query_extra.'');
$results->execute();
return $results;
}
}
这是实际页面中的代码:
And this is the code in the actual page:
include_once 'Classes/SelectQuery.php';
$SelectQuery = new SelectQuery();
$query_table = 'category';
$query_extra = '';
$SelectQuery->db_select($query_table, $query_extra);
$date = $db_select->$result;
$date = mysqli_fetch_assoc($result);
echo $date;
while($categories = $result->fetch_assoc())
{
echo '<p>';
echo $categories['ID'].' ';
echo $categories['Name'].'</p>';
while($forums = $result_forum->fetch_assoc())
{
echo $categories['Name'].'</p>';
}
}
问题不在课堂上(我认为),它在实际页面中我正在尝试获取我想要的信息,在此之前没有错误:
The problem isnt in the class(i think), it's in the actual page when i'm trying to get the info that i want, there is no error until here:
$SelectQuery->db_select($query_table, $query_extra);
但在那之后,当我试图真正得到信息时,有很多错误,我可能做错了...我想知道我该怎么办呢,谢谢:)
我的尝试:
我尝试过很多像我说的那样的东西,我在这方面很新,我不知道它为什么不起作用...
but after that line when i'm trying to really get the info there is a lots of errors and i'm probably doing it wrong... i would like to know how can i fix it, thanks :)
What I have tried:
I tried a lots of things like i said, i'm pretty new at this and i have no idea why it's not working...
推荐答案
query_table ,
query_table,
query_extra){
//
query_extra) { //
result = mysqli_query(
result = mysqli_query(
这篇关于Php OOP选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!