2016-08-28 3 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 자이나교. 문제가 해결되었습니다 – 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();