2

I'm trying to use php to read data from a mysql database. I'm new to php and I can't figure out what I did wrong here (In the original code the variables for the connection are declared, I only didn't want to post them here)

Here is what I've tried:

<?php


$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD);

if (!$con)

    {

        die('Could not connect: ' . mysql_error());

    }

$db = mysql_select_db(DB_DATABASE, $con);

$stmt = $db->prepare("SELECT * FROM exhibits");

$stmt->execute();

$stmt->store_result();

$stmt->bind_result($id, $nr, $vnr, $title, $text, $pic1, $pic2, $pic3);

$items = array();

while($stmt->fetch()){
    $temp = array();
    $temp['id'] = $id; 
    $temp['nr'] = $nr; 
    $temp['vnr'] = $vnr; 
    $temp['title'] = $title; 
    $temp['text'] = $text; 
    $temp['pic1'] = $title; 
    $temp['pic2'] = $title;
    $temp['pic3'] = $title;
    array_push($items, $temp);
    }


echo json_encode($items);

$conn->close();

?>
Alissa
  • 21
  • 1

0 Answers0