1 Replies - 171 Views - Last Post: 10 August 2017 - 12:55 AM

#1 Bicklo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-November 16

mysql_connect to PDO

Posted 09 August 2017 - 03:14 PM

I am struggling for 2 days now to convert some mysql_connect pages to PDO, so far this works

<?php
 
try {
$db = new PDO("mysql:host=localhost;dbname=graphix_effect;charset=utf8;", "graphix_effect", "damast");
} catch (PDOException $e) {
die("Could not connect to database");
}
 
?>



Now my question is how to convert this code to PDO

$vtest = mysql_query("SELECT d1, d2, d3 FROM items WHERE item='Afdeling'");
    
    


while ($row = mysql_fetch_array($vtest)){
    $doen1 = $row['d1']; 
    $doen2 = $row['d2'];
    $doen3 = $row['d3'];
    

}
    

if ($doen1 !=NULL){   
$xtest = mysql_query("SELECT * FROM $doen1");
    
    


while ($row = mysql_fetch_object($xtest)){
  echo '<p><a href=""><div class="namen">'.$row->naam.'</div></a></p>'; 
    
   

}
}



Can anyone tell me how to achieve please.

Is This A Good Question/Topic? 0
  • +

Replies To: mysql_connect to PDO

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4128
  • View blog
  • Posts: 13,023
  • Joined: 08-June 10

Re: mysql_connect to PDO

Posted 10 August 2017 - 12:55 AM

This first and foremost looks like a major database design failure. I would have to ask, why there are table names associated with an item (i.e. you store application structure where there should only be application data).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1