I'm trying a new way to connect and retrieve data from database but I couldn't know why when I execute on boolean I added and delete the search_id but still have the same problem, I tried to change the bind_result place before I execute and still have the same problem.
Table search:
    #   Name    Type
    1   search_idPrimary    int(11)
    2   activity    varchar(255)
3   description varchar(5000)
    4   activity_img    varchar(255)
    5   origin  varchar(255)
    6   to  varchar(255)
    7   date_from   date
    8   date_to date
 define('DB_HOST', 'localhost');
 define('DB_USER', 'root');
 define('DB_PASS', '');
 define('DB_NAME', 'website5.0');
 //connecting to database and getting the connection object
 $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
 //Checking if any error occured while connecting
 if (mysqli_connect_errno()) {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 die();
 }
 $stmt = $conn->prepare("SELECT activity, description, activity_img, 
 origin, 
 to, date_from, date_to FROM search;");
$stmt->execute();
$stmt->bind_result( $activity, $description, $activity_img, $origin, $to, 
$date_from, $date_to);
$search = array();
while($stmt->fetch()){
$temp = array();
$temp ['activity'] = $activity;
$temp ['description'] = $description;
$temp ['activity_img'] = $activity_img;
$temp ['origin'] = $origin;
$temp ['to'] = $to;
$temp ['date_from'] = $date_from;
$temp ['date_to'] = $date_to;
$array_push ($search, $temp);
 }
  echo json_encode($search);
   ?>
I can't find the error:
Fatal error: Uncaught Error: Call to a member function execute() on boolean in C:\xamppnew\htdocs\android\search.php:22 Stack trace: #0 {main} thrown in C:\xamppnew\htdocs\android\search.php on line 22
 
No comments:
Post a Comment