SQLite3查询错误

时间:2016-08-28 04:36:28

标签: php sqlite

我的代码需要一些帮助。我收到这个错误:

  

PHP警告:SQLite3 :: query():无法准备语句:1,=附近:第16行/var/www/html/image.php语法错误

     

PHP致命错误:未捕获错误:在/var/www/html/image.php中调用布尔成员函数fetchArray():17`

     

堆栈追踪:

     

0 {main}

     

在第17行的/var/www/html/image.php中抛出

这是我的代码:

<?php
error_reporting(E_ALL ^ E_NOTICE);
Header("Content-type: image/png");
$im = imagecreate(304, 214);
$blanco = imagecolorallocate($im, 255, 255, 255);
imagerectangle($im, 0, 0, 304, 214, $blanco);
$rojo = imagecolorallocate($im, 255, 0, 0);
$verde = imagecolorallocate($im, 0, 255, 0);
$azul = imagecolorallocate($im, 0, 0, 255);
$amarillo = imagecolorallocate($im, 255, 255, 0);
$violeta = imagecolorallocate($im, 46, 49, 146);
$naranja = imagecolorallocate($im, 242, 101, 34);
$negro = imagecolorallocate($im, 0, 0, 0);

if ($db = new SQLite3 ('/var/www/html/db/SeriesDb.sqlite')) {
    $q = $db-> query("SELECT * FROM tbl_Series where id "= .$_REQUEST["id"]);
    while ($row = $q-> fetchArray()) {
        $id = $row[0];
        $dayweek = date("N", strtotime($row[1]));
        $serie = explode(" ",$row[2]);
    }
} else {
    die("error");
}

switch ($dayweek) {
    case 7: $color = $rojo;
        break;
    case 6: $color = $naranja;
        break;
    case 5: $color = $amarillo;
        break;
    case 4: $color = $verde;
        break;
    case 3: $color = $azul;
        break;
    case 2: $color = $violeta;
        break;
    case 1: $color = $negro;
}
$j = 0;
$y = 0;
$x = 0;

for ($i = 0; $i < 70; $i++) {
    $j++;
    if ($j > 10)
        $j = 1;
    $x = 30 * $j - 28;
    $y = $i % 10 == 0 ? 2 + ($i / 10) * 30 : $y;
    imagerectangle($im, $x, $y, $x + 30, $y + 30, $negro);
    if (in_array($i + 1, $serie))
        imagefilledrectangle($im, $x + 1, $y + 1, $x + 30 - 1, $y + 30 - 1, $color);
}
Imagepng($im);
Imagedestroy($im);
$db->close();

问题是什么?

2 个答案:

答案 0 :(得分:1)

:help gui-colors 符号似乎位于您要连接'\%1l^.\{,50}' 的字符串文字之外。它应该是这样的:

=

但是,最好避免连接并使用预先准备好的声明:

$_REQUEST["id"]

答案 1 :(得分:0)

看起来您的查询无法正常生成。建议使用prepare语句将运行时参数添加到查询中。你可以使用this教程。

相关问题