2016-08-28 62 views
0

我需要一些帮助,我的代码。我得到这个错误:SQLite3查询错误

PHP Warning: SQLite3::query(): Unable to prepare statement: 1, near = : syntax error in /var/www/html/image.php on line 16

PHP Fatal error: Uncaught Error: Call to a member function fetchArray() on boolean in /var/www/html/image.php:17`

Stack trace:

0 {main}

thrown in /var/www/html/image.php on line 17

这是我的代码:

<?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(); 

还有什么问题呢?

+0

非常感谢你; cartant和sandesh jain。问题已解决 – user2257002

+0

您应该接受答案,以便您的问题不再列为未答案:http://stackoverflow.com/help/someone-answers – cartant

回答

0

它看起来像你的查询没有正确生成。建议使用prepare语句将运行时参数添加到查询中。你可以去this教程。

0

=符号似乎超出了您要连接的字符串文字$_REQUEST["id"]。它应该是这样的:

$q = $db->query("SELECT * FROM tbl_Series where id = " . $_REQUEST["id"]); 

但是,它会更好,以避免级联和使用事先准备好的声明:

$stmt = $db->prepare("SELECT * FROM tbl_Series where id = :id"); 
$stmt->bindValue(":id", $_REQUEST["id"], SQLITE3_TEXT); 
$q = $stmt->execute();