PHP-Mysqli |中文我正在尝试输出数据,但我一直在获取空数组
我正在尝试从数据库中获取用户信息,但是它一直给我一个空数组.
代码:i.stack.imgur.com/Op4HB.png
i'm trying to get user information from database, but it keep giving me an empty array.
code : i.stack.imgur.com/Op4HB.png
$information = array();
$user = 'admin';
$myuser = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($info = $myuser->prepare("SELECT id,username,email,bd,firstname,lastname,gender,ppicture,cpicture FROM members WHERE username = ?")) {
$info->bind_param("s", $user);
/* execute query */
$info->execute();
/* get result */
$result = $info->get_result();
/* bind result variables */
$info->bind_result($information['id'],$information['username'],$information['email'],$information['birthday'],$information['first_name'],$information['last_name'],$information['gender'],$information['profile_picture'],$information['cover_picture']);
$info->fetch();
$rows = $result->num_rows;
$info->close();
}
if (!$rows) {
redirect('http://example.com/');
} else {
print_r($information);
}
这就是我得到的:
有人可以帮我吗?我一直都在使用mysqli,但是我不知道这次出了什么问题.
can someone help me in this ? i use mysqli all the time but i don't know what went wrong this time.
谢谢.
我自己修复了
还是谢谢!
<?php
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$query = "SELECT id,username,email,bd,firstname,lastname,gender,ppicture,cpicture FROM members WHERE username = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $user);
$stmt->execute();
$res = $stmt->get_result();
$rows = $res->num_rows;
$information = $res->fetch_assoc();
if($rows == 0 ) {
redirect("http://example.com");
}
print_r($information);
?>
PS:index.php要求使用account.php,以便从那里获取' $ user '
PS: account.php is being required by index.php so it gets '$user' from there
输出
Array([id] => 15 [username] => admin [email] => admin@theboat.tn [bd] => 2017-02-07 [firstname] => Saif [lastname] => Eddin [性别] =>男性[ppicture] => 1f4c1b47a3910039e60851c453ae4d80_a.jpg [cpicture] => default_c.jpg)
Array ( [id] => 15 [username] => admin [email] => admin@theboat.tn [bd] => 2017-02-07 [firstname] => Saif [lastname] => Eddin [gender] => male [ppicture] => 1f4c1b47a3910039e60851c453ae4d80_a.jpg [cpicture] => default_c.jpg )