I am trying to store URL Image paths into MySQL DB. But i am not getting any results with my code.
- Why is it not storing anything?
- Would it be better just to store the image name or the entire path? target example: "www.example.com/medium/imagename.jpg"
Table Name: urlimage
id: autoincrement
image_name
Php code for inserting data into DB
<?php
$images = explode(',', $_GET['i']);
$path = Configuration::getUploadUrlPath('medium', 'target');
if(is_array($images)){
$objDb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);
$objDb->exec('SET CHARACTER SET utf8');
$sql = "INSERT INTO `urlImage` (`image_name`) VALUES ";
foreach ($images as $image) {
//echo '<div><p>' . $path . $image . '</p><img src="' . $path . $image . '" /></div>';
$value[] = "(".$path.$image.")"; // collect imagenames
}
$sql .= implode(',', $value).";"; //build query
$objDb->query($sql);
}
?>
print_r($sql)just before$objDb->query($sql);php.iniseterror_reporting = E_ALL | E_STRICTanddisplay_errors = Onif you have not done so.$objDb->query($sql);