Call to undefined method mysqli_result::getColumnNames()

Topics: User Forum
Aug 16, 2012 at 1:34 PM
Edited Aug 16, 2012 at 1:50 PM

Hi everyone !

I tried to use the script given on the phpexcel homepage, in order to get some content from my SQL database, but it doesn't work...

Here's the snippet of code :


/** PHPExcel */
require_once '../include/PHPExcel.php';

/** DB and stuff */

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Database with existing object
$sql = "SELECT * FROM `client` ORDER BY `id_client` ASC";
$res = $db->query($sql) OR die ("Erreur :" .$this->db->error);

// First Row (Names)
foreach ($res->getColumnNames() as $coluna=>$num) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow ($num,1,$coluna);

// Other Rows (Data)
$i = 2;
while ($row = $res->fetchrow()) {
foreach ($row as $col=>$dado) $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow ($col,$i,$dado);

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/');
header('Content-Disposition: attachment;filename="table.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
In my browser I get the following error :

Fatal error: Call to undefined method mysqli_result::getColumnNames() in [...] on line 20

Any idea ?
Thanks in advance

Apache/2.2.22 (Win32) PHP/5.4.4