[英]SQL Query Works, But Not In PHP
I tested and successfully used this SQL code below to input data into a database. 我测试并成功使用下面的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')
Now I'm trying to integrate it into PHP like this: 现在,我试图像这样将其集成到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;
But nothing gets inserted and I'm not getting any error. 但是什么也没插入,我没有任何错误。 The only difference is that in this one I'm defining id as $dbid, and before I hard-coded it in the "values" section of the query. 唯一的区别是,在此代码中,我将id定义为$ dbid,并且在将其硬编码到查询的“ values”部分中之前。
Can somebody please point out why this code is not working successfully? 有人可以指出为什么此代码无法成功工作吗? Thank you. 谢谢。
just remove "."
只需删除"."
before VALUES
. 在VALUES
之前。 try this 尝试这个
and you missed mysqli_query()
而您错过了mysqli_query()
$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 ";
edit : if it Oracle then use this 编辑:如果它Oracle然后使用此
$compiled = oci_parse($db, $query); //-- $db is your connection to database variable
oci_bind_by_name($compiled, ':id', $id); // --your id
oci_execute($compiled);
The two queries above are not equal, as they use different data types (int v string). 上面的两个查询不相等,因为它们使用不同的数据类型(int v字符串)。
The first casts as string, the second casts as int. 第一个强制转换为字符串,第二个强制转换为int。 Change the INSERT query to read: 将INSERT查询更改为:
$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";`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.