0
我是一个一流的执行语句mysql和我不知道如何打印返回数组变量如何在php中的表中打印行数组?
class Db {
// The database connection
protected static $connection;
public function connect() {
// Try and connect to the database
if(!isset(self::$connection)) {
self::$connection = new mysqli('localhost','root','123456','dbGanaderia');
}
// If connection was not successful, handle the error
if(self::$connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
return self::$connection;
}
public function query($query) {
// Connect to the database
$connection = $this -> connect();
// Query the database
$result = $connection -> query($query);
return $result;
}
public function select($query) {
$rows = array();
$result = $this -> query($query);
if($result === false) {
return false;
}
while ($row = $result -> fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
这时候我所说的方法来执行SELECT语句的行返回一个数组,但我不”牛逼硝酸钾如何打印......如果我这样做printr($行)我verefy其从数据库返回的声明
$db = new Db();
$rows = $db -> select("SELECT *FROM user");
if ($rows == true) {
echo "<table border = '1'> \n";
echo "<tr><td>name</td></tr> \n";
while($row = mysql_fetch_array($rows)) {
echo "<tr><td>".$row['1']."</td></tr> \n";
}
echo "</table> \n";
} else {
echo "¡ No data !";
}
我在哪里错了?
'mysql_fetch_array'不工作。 – chris85
我明白了,没错 –