2016-11-28 7 views
0

私はSELECT文を実行するメソッドを呼び出したときに「行が配列を返すが、私はドンこのクラスだステートメントのmysqlを実行し、私は戻り配列変数を印刷する方法がわからないPHPのテーブルに行mysql配列を出力するにはどうしたらいいですか?

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; 
    } 
} 

tが、私はこのprintr($行)を行う場合、私はそのデータベースが私は間違っ

$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 !"; 
} 

から戻っ声明ことverefy ...印刷する方法自演しましたか?

+1

mysqli' 'と' mysql_fetch_array' doesntの仕事にフェッチ変更

mysqli_機能

でmysql_関数を混合しています。 – chris85

+0

私はそれを得ました、それは正しいです –

答えて

0

あなたの

$r = mysqli_fetch_array() 
+0

私はあなたが言ったように試みたが、いいえ –

関連する問題