1

PDO を使用してデータベースに int を挿入しようとしていますが、何らかの理由で次のエラーで失敗し続けます。

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 を使用しても失敗します。バインディングの代わりに IE 0。

※質問内容に誤りがありました。

4

1 に答える 1

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'
于 2012-11-14T21:24:00.603 に答える