Hi I have started to change my mysql to PDO before my code starts getting large and risk of causing problems i have tried changing a section of my code but the screen shows as white this is my original code:
class SelectList
{
protected $conn;
public function __construct()
{
$this->DbConnect();
}
protected function DbConnect()
{
include "db_config.php";
$this->conn = mysql_connect($host,$user,$password) OR die("Unable to connect to the database");
mysql_select_db($db,$this->conn) OR die("can not select the database $db");
return TRUE;
}
public function ShowPrinciple()
{
$sql = "SELECT principle.principle_id,principle.description,principle.section_id,COUNT(media.principle_id) as media_count
FROM principle
LEFT OUTER JOIN media ON principle.principle_id = media.principle_id
AND principle.section_id = media.section_id
WHERE principle.section_id={$_POST['id']}
GROUP BY principle.principle_id,principle.description";
$res = mysql_query($sql,$this->conn);
$principle = '<option value="%">choose...</option>';
while($row = mysql_fetch_array($res))
{
$principle .= '<option value="' . $row['principle_id'] . '">' . $row['description']. '...('.$row['media_count'].') </option>';
}
return $principle;
}
}
$opt = new SelectList();
I have tried a simple query to start off with to change but I seem to have done something wrong could some one point out to me I'm positive it will be something I have changed.
This is the code that I have currently got:
class SelectList
{
$host = '127.00.00.00';
$user = 'user';
$password = 'password';
$db = 'database';
try{
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $password);
echo 'connected to the database<br />';
public function ShowPrinciple()
{
$stmt = $conn -> prepare(
"SELECT principle.principle_id,principle.description,principle.section_id,COUNT(media.principle_id) as media_count
FROM principle
LEFT OUTER JOIN media ON principle.principle_id = media.principle_id
AND principle.section_id = media.section_id
WHERE principle.section_id={$_POST['id']}
GROUP BY principle.principle_id,principle.description");
$q = $conn->query($stmt) or die("failed!)";
$principle = '<option value="%">choose...</option>';
while($row = fetchAll($q))
{
$principle .= '<option value="' . $row['principle_id'] . '">' . $row['description']. '...('.$row['media_count'].') </option>';
}
return $principle;
}catch(PDOException $e){
echo $e->getMessage();
}
}
$opt = new SelectList();
Any help would be much appreciated.