我嘗試使用PDO來顯示從數據庫表中的值顯示在PHP表中的值,但此時它顯示了一個錯誤如何使用PDO
"Fatal error: Call to undefined method ManageUsers::fetchAll()"
請提供解決方案來解決這個問題?
列表seller.php
<?php
include "C:/wamp/www/Super_Admin_MangoAir/classes/class.ManageUsers.php";
$sellers = new ManageUsers();
//$sellers->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
while ($row = $sellers->fetchAll(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><?php echo $row['company_name']; ?>
<span class="pull-right-container">
<small class="label pull-center bg-green">Premium Member</small>
</span>
</td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['mobile']; ?></td>
<td><?php echo $row['count_free']; ?></td>
<td><?php echo $row['count_travel']; ?>
<span class="pull-right-container">
<small class="label pull-center bg-green">Paid</small>
</span>
</td>
<td><a href=""><button type="button" class="btn btn-flat btn-default btn-sm disabled">Already Paid</button></a></td>
</tr>
<?php } ?>
class.ManageUsers.php
<?php
class ManageUsers{
include "C:/wamp/www/Super_Admin_MangoAir/classes/class.database.php";
public $link;
function __construct(){
$db_connection = new dbConnection();
$this->link = $db_connection->connect();
return $this->link;
}
function seller_list($result){
$result = $this->link->prepare("SELECT company_name,email,phone,count_free,count_travel FROM login");
$result->execute();
}
}
?>
class.database.php
<?php
class dbConnection{
protected $db_conn;
public $db_name='company';
public $db_user='root';
public $db_pass='';
public $db_host='localhost';
function connect(){
try{
$this->db_conn=new PDO("mysql:host=$this->db_host;dbname=$this->db_name",$this->db_user,
$this->db_pass);
return $this->db_conn;
}
catch(PDOException $e){
return $e->getMessage();
echo 'errorrrrrrrr';
}
}
}
?>
從構造函數中刪除
return $this->link
,並呼籲使用fetchall以及存在'ManageUsers' – Drew