Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO - Changing old mysql_fetch_object

Tags:

mysql

pdo

I have a small problem by using PDO instead of mysql_fetch_object.

I tried to find something to replace it but nothing seems to work.

First my link is done :

$link = new PDO('mysql:host='.$local.';dbname='.$nomBase.'', $user, $password, $pdo_options);

Here is my code :

while($row = mysql_fetch_object($result)){
$data1=$row->nickname;
$data2=$row->id_contact;
echo ("<option ");
if ($handled==$data2) { echo ("selected "); } 

Thanks for your help

like image 494
user1369609 Avatar asked Aug 17 '26 06:08

user1369609


1 Answers

You should change it to :

while($row = $result->fetch(PDO::FETCH_OBJ)){
...
}

You will find more information about it here : PDOStatement Fetch

It is a good choice to change for PDO ! Need more people like you ;).

like image 56
ChapMic Avatar answered Aug 18 '26 20:08

ChapMic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!