I have a created a new table (colours) which has id and hex as columns, all existing ids are kept in the pics table along with the path of the picture, which will go into the new colours table with the many hex values. I am using a class to extract the prominent colours from the picture as array of hex values.
This is the code so far:
$data = $conn->query('SELECT id,pic_path FROM pics WHERE pic_id = 1231');
while($row = $data->fetch()) {
$image = new ColorsOfImage('images/'.$data['pic_path']);
$colors = $image->getProminentColors();
foreach($colors as $key => $val)
{
$sql = "INSERT INTO colours (pic_id,colour) VALUES (:pic_id,:colour)";
$q = $conn->prepare($sql);
$q->execute(array(':pic_id'=>$data['pic_id'],':colour'=>$val));
}
}
But I get this error:
Fatal error: Cannot use object of type PDOStatement as array
This is how it should look like this once it's populated:
