Bug #75110 [Com]: Dont iterate foreach
Edit report at https://bugs.php.net/bug.php?id=75110&edit=1
ID: 75110
Comment by: subjective@php.net
Reported by: porfi_miramontes at hotmail dot com
Summary: Dont iterate foreach
Status: Open
Type: Bug
Package: *General Issues
Operating System: ubuntu16.04.1
PHP Version: 7.0Git-2017-08-23 (snap)
Block user comment: N
Private report: N
New Comment:
You do not access the actual fields, but the record array/object. Here is no automatic conversion of
an array/object to CSV, look up fputcsv().
Previous Comments:
------------------------------------------------------------------------
[2017-08-23 18:05:46] porfi_miramontes at hotmail dot com
Description:
------------
Dont print values from array obtained from database use foreach loop
Test script:
---------------
<?php
try {
$base=new
PDO('mysql:host=localhost;dbname=mydatabase','root','12345678');
$base->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$base->exec("SET CHARACTER SET UTF8");
$reg=$base->query("SELECT * FROM articles WHERE client='Myclient' ORDER BY
article_state desc limit 1,2")->fetchAll(PDO::FETCH_OBJ);
foreach($reg as $articles=>$value)
{
echo $value;
}
}
catch (Exception $e)
{
die ("Error ".$e->getMessage());
echo "Line error : ".$e->getLine();
}
?>
Expected result:
----------------
Myarticle1,Desc1,Desc2
Myarticle2,Desc1,Desc2
Myarticle3,Desc1,Desc2
.
.
.
.
.
.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75110&edit=1
Thread (3 messages)