2012-11-14 4 views
1

내가 PDO를 사용하여 데이터베이스에 int를 삽입하기 위해 노력하고있어와 MySQL의 데이터로 INT를 삽입 할 수 없습니다 만, 몇 가지 이유로이 오류와 함께 실패 계속 :는 PDO

: 여기

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2031 ' in C:\vhosts\jpl\admin\add_project.php:119 Stack trace: #0 C:\vhosts\jpl\admin\add_project.php(119): PDOStatement->execute() #1 C:\vhosts\jpl\admin.php(25): include('C:\vhosts\jpl\a...') #2 {main} thrown in C:\vhosts\jpl\admin\add_project.php on line 119 

코드입니다

 $projectAdd = $database->prepare("INSERT INTO projects (title, short_description, long_description, image_location, display)VALUES ('test', 'test', 'test', ?, :integer)"); 
     $projectAdd->bindParam(1, $test); 
     $projectAdd->bindParam(':integer', $value, PDO::PARAM_INT); 

     $test = "testbind"; 
     $value = 1; 
     $projectAdd->execute(); 

직접적인 int를 사용하더라도 여전히 실패합니다. I.E 0 바인딩 대신.

* 편집에서 질문에 오류가 발생했습니다.

+5

왜 두 번 PARAM 1을 결합하려고? –

+0

당신은 질문을 게시 할 수 있습니까? 클라이언트에서 직접 실행하려고하면 어떻게됩니까? – Cfreak

+2

$ projectAdd-> bindParam (1, $ testint);를'$ projectAdd-> bindParam (2, $ testint);' –

답변

4

시도 :

$projectAdd = $database->prepare("INSERT INTO projects (title, short_description, long_description, image_location, display)VALUES ('test', 'test', 'test', ?, ?)"); 
//The variables need to be defined before binding. 
$test = "testbind"; 
$testint = 1; 
$projectAdd->bindParam(1, $test); 
$projectAdd->bindParam(2, $testint); //change '1' to '2'