Hello everyone, this mysql_deprecated works very fine and retrieves information but when i tried
moving it to PDO it displays nothing. can someone help me
thank you
working mysql_deprecated.php
<?php
require('config.php');
$user = $_SESSION['log']['username'];
$sql = "SELECT * FROM users WHERE username='$user' OR friend='$user' AND status = 'accepted'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
echo 'fine';
if ($row['friend'] != $user) { $friend = $row['friend']; } else { $friend = $row['username']; }
$query = "SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post WHERE
(username = '$friend' OR username = '$user') ORDER BY post_id DESC LIMIT 5";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo 'data retrieved successfully';
}
}
?>
pdo.php
<?php
$db = new PDO (
'mysql:host=localhost;dbname=testing',
'root', // username
'' // password
);
$user = $_SESSION['log']['username'];
$sql = $db->prepare('
SELECT * FROM users
WHERE username= ? OR friend = ? and status = accepted');
$sql->bindParam(1, $user, PDO::PARAM_STR);
$sql->bindParam(2, $user, PDO::PARAM_STR);
$sql->execute();
while($row = $sql->fetch())
{
echo 'fine';
if ($row['friend'] != $user) {
$friend = $row['friend'];
} else {
$friend = $row['username'];
}
$query = $db->prepare('
SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post WHERE
(username = :username OR username = :username1) ORDER BY post_id DESC LIMIT 5
');
$query->execute(array(
':username' => $friend,
':username1' => $user ));
$result = $query->fetch();
while ($row = $result->fetch())
{
echo 'data retrieved successfully';
}
}
?>