I am storing text in a database table. Some of the saved text have apostrophes. Using PDO prepare statements I have been able to get them into the table, but when I SELECT them the text is cut off at the apostrophe. Can anyone tell me what I am doing wrong. I want single quotes to be escaped in in the Description field.
Code:
<?php
$config['db'] = array(
'host' =>'localhost',
'username' =>'root',
'password' =>'',
'dbname' =>'userdata'
);
$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname=' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
$db->setATTRIBUTE(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $db->prepare("SELECT test . Link, Image_directory, Description FROM test ORDER BY ID DESC");
$query->execute(array('Description'));
$row = $query->fetch(PDO::FETCH_ASSOC);
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$Link = $row['Link'];
$Image = $row['Image_directory'];
$Desc = $row['Description'];
//proper syntax for creating my anchor tag with image inside
{
echo "<a href=",$Link,">";
echo "<img src='";
echo $Image;
echo "' ";
echo "title='";
echo $Desc;
echo"'>";
echo "</a>";
}
}
//execute query
?>