我测试并成功使用下面的 SQL 代码将数据输入数据库。
INSERT INTO hraps (id, firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) values(111111, 'World', 'Hello', 'Male', '2007', '1', '2', '0')
现在我正在尝试将它集成到 PHP 中,如下所示:
$query = "INSERT INTO hraps (firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) "
."values('".$this->firstname."','".$this->lastname."','".$this->gender."','".$this->year_of_1st_rappel."',".$this->count_offset_proficiency.",".$this->count_offset_operational.",".$this->spotter.") returning id into :id";
$dbid = "";
$binds = array();
$binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128);
//echo $query;
$result = mydb::cxn()->query($query, $binds);
$this->id = $dbid;
但是什么都没有插入,我也没有收到任何错误。唯一的区别是,在这一个中,我将 id 定义为 $dbid,并且在我将其硬编码到查询的“值”部分之前。
有人可以指出为什么这段代码不能成功运行吗?谢谢你。