我写了一个小代码,希望它能解决查询。
//Query to be executed;
$qry="select * from `tableName`";
//Performs a query on the database;
//here conn is a link identifier returned by mysqli_connect or mysqli_init function;
$result=mysqli_query($conn,$qry);
//Gets the number of rows in a result;
$rowcount=mysqli_num_rows($result);
//Fetches all result rows as an associative array;
$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
//Iterating each row;
for($i=0;$i<$rowcount;$i++)
{
echo "<br> ".$row[$i]['`column_name_1`']." ".$row[$i]['`column_name_2`']." ".$row[$i]['`column_name_3`'];
}
示例
数据库表
Mysql 表快照
代码
//here conn is a link identifier returned by mysqli_connect or mysqli_init function;
$conn = mysqli_connect("localhost","root","","nsgdb") or die('Error connecting to MySQL server.');
//Query to be executed;
$qry="select * from users";
//Performs a query on the database;
$result=mysqli_query($conn,$qry);
//Gets the number of rows in a result;
$rowcount=mysqli_num_rows($result);
//Fetches all result rows as an associative array;
$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
//Iterating each row;
for($i=0;$i<$rowcount;$i++)
{
echo "<br> ".$row[$i]['id']." ".$row[$i]['user']." ".$row[$i]['pass'];
}
代码的输出