Select 全部来自数据库
Select all from the db
我需要打印数据库中的所有用户,但我该怎么做?我不能绑定 baram 因为没有东西可以绑定?
这是我的代码:
session_start();
require 'inc/connect.php';
$hey = $mysqli->prepare("SELECT * FROM user");
$hey->execute();
$hey->bind_result($all);
$hey->fetch();
$hey->close();
echo $all;
如果table user有七列,给出bind_result
七个变量名:
$hey->bind_result($column_one, $column_two, $column_three, $column_four, $column_five, $column_six, $column_seven);
当然,使用反映所表示数据性质的变量名称。
现在一起:
session_start();
require 'inc/connect.php';
$hey = $mysqli->prepare("SELECT * FROM user");
$hey->execute();
$hey->bind_result($id, $fname, $lname, $email, $phone, $addy, $age);
while ( $hey->fetch() ) {
echo "$id $fname $lname $email $phone $addy $age<br>";
}
$hey->close();
我更喜欢使用 SQL 明确表示并在结果中调用我想要的列:
SELECT id, fname, lname, email, phone, addy, age FROM user
...为了保护我在案例列中的查询稍后添加到 table。
我需要打印数据库中的所有用户,但我该怎么做?我不能绑定 baram 因为没有东西可以绑定?
这是我的代码:
session_start();
require 'inc/connect.php';
$hey = $mysqli->prepare("SELECT * FROM user");
$hey->execute();
$hey->bind_result($all);
$hey->fetch();
$hey->close();
echo $all;
如果table user有七列,给出bind_result
七个变量名:
$hey->bind_result($column_one, $column_two, $column_three, $column_four, $column_five, $column_six, $column_seven);
当然,使用反映所表示数据性质的变量名称。
现在一起:
session_start();
require 'inc/connect.php';
$hey = $mysqli->prepare("SELECT * FROM user");
$hey->execute();
$hey->bind_result($id, $fname, $lname, $email, $phone, $addy, $age);
while ( $hey->fetch() ) {
echo "$id $fname $lname $email $phone $addy $age<br>";
}
$hey->close();
我更喜欢使用 SQL 明确表示并在结果中调用我想要的列:
SELECT id, fname, lname, email, phone, addy, age FROM user
...为了保护我在案例列中的查询稍后添加到 table。