我不知道缺少什么或为什么不显示数据。如果我不使用准备好的语句,我的代码就可以工作。当我使用准备好的语句时,代码似乎不再工作了。
数据库.php
Class Database{
public $mysqli;
public function __construct($db_host, $db_user, $db_password, $db_name){
$this->con = new mysqli($db_host, $db_user, $db_password, $db_name);
}
public function selectUserInfo($id){
$stmt = $this->con->prepare("SELECT * FROM users WHERE os_id = ?");
$stmt->bind_param("s", $id);
if($stmt->execute() == FALSE){
trigger_error($stmt->error, E_USER_ERROR);
}else{
$data = array();
while($row = $stmt->fetch()){
$data[] = $row;
}
return $data;
}
}
}
配置文件
define("DBHOST","somehost");
define("DBUSER","someroot");
define("DBPASS","somepassword");
define("DB","my_database");
这就是我在我的页面上显示它的方式。
require 'global/db.php';
require_once 'config.php';
$db = new Database(DBHOST, DBUSER, DBPASS, DB);
$data = $db->selectUserInfo($_GET['name']);
foreach ($data as $key) {
# code...
echo $key['os_fname'];
}