Php 无法使用PDO将int插入mySql数据

Php 无法使用PDO将int插入mySql数据,php,pdo,Php,Pdo,我试图使用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): PDOStateme

我试图使用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,它仍然失败。即0而不是绑定

*编辑在问题上出错。

请尝试:

$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'
尝试:


为什么要尝试绑定param 1两次?可以发布查询吗?如果您尝试直接在客户机上执行它会发生什么情况?尝试更改
$projectAdd->bindParam(1,$testint)
$projectAdd->bindParam(2,$testint)为什么尝试绑定参数1两次?可以发布查询吗?如果您尝试直接在客户机上执行它会发生什么情况?尝试更改
$projectAdd->bindParam(1,$testint)
$projectAdd->bindParam(2,$testint)