i tried to switch my code from mysql to PDO everything seems to be working because i don't get any error but the contents of the webpages don't show up.
this is my DB connection structure
try {
$conn = new PDO('mysql:host=localhost;dbname=***', '***', '***', array(PDO::ATTR_PERSISTENT => true));
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Problem with connection ".$e->getMessage();
}
so i tried a new page with one of the functions i have in my library using PDO and it displayed
<?php
require_once('functions/generalfunctions.php');
try {
$conn = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "success";
} catch(PDOException $e) {
echo "I'm sorry there is a problem with your operation..";
file_put_contents( 'dbErrors.txt', $e->getMessage(), FILE_APPEND );
}
try{
$query = $conn->prepare("SELECT * FROM categories ORDER BY title");
$query->execute();
$i = 0;
while($output = $query->fetch()){
echo '<li><a href="category.php?cat_id='.encrypt_id($output["id"]).'" class="parent" rel="'.$i.'">'.$output["title"].'</a>'. "\n" .'<ul class="child'.$i.'">';
$stm = "SELECT title,id FROM sections WHERE cat_id=".$output["id"]." ORDER by title";
$query = $conn->prepare($stm);
$query->execute();
while($out = $query->fetch()){
$stm = "SELECT count(sec_id) AS topic_count FROM topic WHERE sec_id =".$out["id"];
$qry = $conn->prepare($stm);
$qry->execute();
$cnt = $qry->fetch();
echo "<li>";
echo '<a href="sections.php?sec_id='.encrypt_id($out["id"]).'&cat_id='.encrypt_id($output["id"]).'">'.$out["title"]."</a><span id=\"cnt_no\" class=\"badge badge-inverse\">".$cnt["topic_count"];
echo "</span></li>";
}
echo "</ul>\n</li>";
$i++;
}
}catch(Exception $e){
die(header('location: http://localhost/test'));
}?>
so i don't know where the problem is from. Help please
i just figured out one of the main problems... it says
Notice: Undefined variable: conn in C:\wamp\www\xxx\functions\xxx.php on line 673
and $conn is the name of the variable(object) holding the instance of the PDO connection..
What could be the problem now