Thread: Resolved Pdo prepare statement
View Single Post
Old 12-24-2012, 08:34 PM   PM User | #1
Ax3l
New Coder

 
Join Date: Aug 2012
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ax3l is an unknown quantity at this point
Pdo prepare statement

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
?>

Last edited by Ax3l; 12-25-2012 at 01:25 AM.. Reason: Resolved
Ax3l is offline   Reply With Quote