调用未定义的方法SQLite3 :: execute()

时间:2018-08-13 05:54:16

标签: php sqlite

我创建了三个文件,一个用于处理用户在第二个文件中填写的数据。 Calendar2.php应该将用户创建的事件显示到正确的时间段和人员中,但是我enter image description here收到此代码的错误消息。

“致命错误:在第63行的/net/laguna/h1/m/member300/public_html/calendar2.php中调用未定义的方法SQLite3 :: execute()”

我不确定自己在做什么错。有什么建议么?

#!/usr/local/bin/php
<?php print '<?xml version="1.0" encoding="utf-8" ?> '; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Calendar</title>
<link rel="stylesheet" type="text/css" href="calender.css" />
</head>
<body>
 <div class="container">
<h1>Bruin Family Schedule for
<?php
$mode = "now";
if(isset($_GET['mode'])){
    $mode = $_GET['mode'];
}
date_default_timezone_set('America/Los_Angeles');
//unix timestamp
$unts= time();
// uses the data function to convert unts into the day of the week and so on 
$day_ofweek = date("l",$unts);
$month = date("M",$unts);
$day_ofmonth = date("d",$unts);
$year = date("Y",$unts);
$hour = date("h",$unts);
$minute = date("i", $unts);
$amorpm = date("a",$unts);
echo "$day_ofweek".", "."$month"." "."$day_ofmonth".", "."$year".", "."$hour".":"."$minute"."$amorpm ";
?>
</h1>

<table id="event_table">
   <tr>
       <th class='hr_td_blank'> &nbsp; </th>
       <th class='table_header'>Andy</th>
       <th class='table_header'>Abby</th>
       <th class='table_header'>Elsie</th>
    </tr>
<?php
// this functions gets the hours for the first column, variable t is passed into the function and is used to find the the hour and am/pm
function get_hour_string($t){
//initialize string hour_var 
 $hour_var = "";
   $amorpm = date("a",$t);
   $hour = date("h",$t);

   $hour_var = "$hour".":00"."$amorpm";
   return "$hour_var";
}
function get_events($person, $timestamp){
    $database = "dbyourusername.db";
    try
    {
         $db = new SQLite3($database);
    }
    catch (Exception $exception)
    {
        echo '<p>There was an error connecting to the database!</p>';
        if ($db)
        {
            echo $exception->getMessage();
        }
    }
    $stmt = $db->prepare("SELECT * FROM event_table WHERE person=:person AND time=:time");
    $stmt->bindValue(':person', $person);
    $stmt->bindValue(':time', $timestamp);
    $result = $db->execute($stmt);
    return $result->fetchArray();
}
$hours_to_show = 12;
$u_time = time();
if($mode = 'prev'){
    $u_time -= 3600 *12; 
}else if($mode = 'next'){
    $u_time += 3600*12;
}
//this for loop assigns even an odd row using mod
for($num_rows = 0; $num_rows <= $hours_to_show; $num_rows++)
{

    $andyEventStr = "";
    $abbyEventStr = "";
    $elsieEventStr = "";
    $andyEvent = get_events("Andy", $u_time);
    $abbyEvent = get_events("Abby", $u_time);
    $elsieEvent = get_events("Elsie", $u_time);
    if($andyEvent){
        $andyEventStr = $andyEvent['event_title'] . ": " . $andyEvent['event_message'];  
    }
    if($abbyEvent){
        $abbyEventStr = $abbyEvent['event_title'] . ": " . $abbyEvent['event_message'];  
    }
    if($elsieEvent){
        $elsieEventStr = $elsieEvent['event_title'] . ": " . $elsieEvent['event_message'];  
    }
    echo "<tr class=";
    if ($num_rows % 2 == 0)
       echo '"even_row">';
    else echo '"odd_row">';
    echo '<td class="hr_td">'. get_hour_string($u_time) . "</td>";
    echo "<td>" . $andyEventStr . "</td>";
    echo "<td>" . $abbyEventStr . "</td>";
    echo "<td>" . $elsieEventStr . "</td>";
    echo "</tr>";
    //increase $u_time by an hour each time you go through the loop
    $u_time += 3600;
}
?>
</table>
<form action="" method="GET">
    <input type="hidden" id="mode" value="prev">
    <button type="submit">Prev:</button>
</form>
<form action="" method="GET">
    <input type="hidden" id="mode" value="now">
    <button type="submit">Now: <?php time(); ?></button>
</form>
<form action="" method="GET">
    <input type="hidden" id="mode" value="next">
    <button type="submit">Next:</button>
</form>
</div>
    <p>
    <a href="http://validator.w3.org/check?uri=referer"><img
      src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
  </p>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

您应该在语句句柄而不是数据库上调用execute()

$result = $stmt->execute();

Documentation