【发布时间】:2015-02-22 22:56:49
【问题描述】:
我已经为此工作了大约两天了。我正在尝试为我正在测试的 iOS 移动应用程序设置 PHP 后端,并且我已经获得了与 mysqli 一起工作的基本版本,但我想改用 PDO。
我正在尝试存储从应用程序发送到测试服务器(在我的计算机上)的用户信息。到目前为止,我已经能够用PDO 找出UPDATE 和SELECT - 但是当我到达我的应用程序发出POST 请求以将信息存储在mysql 数据库中的步骤时,会发生什么如下:
a.) 在我传递参数以绑定到 execute() 函数作为参数数组,或者我使用 bindValue 将它们全部单独绑定到一个foreach 在我尝试 execute() 之前循环。如果我的代码到达它没有找到新用户并尝试输入信息的部分,会发生这种情况:
$this->strforvalsie = substr($this->strforvalsie, 0, -1);
$this->stforquee = substr($this->stforquee, 0, -1);
$this->querystring = substr($this->querystring, 0, -1);
$this->hh = $this->makeathing($this->stforquee, $this->querystring);
echo "\n\n".$this->hh."\n\n";
$stmt = $this->db->prepare($this->hh);
foreach ($this->arrayfordat as $key => $value) {
$stmt->bindValue( (string)$key, (string)$value, PDO::PARAM_STR);
}
echo "\n\n\n\n\n".json_encode($streetch)."\n\n\n\n\n\n";
//return 2 - /*** I use this line to exit the code early...before the hang - to see what the variables look like. I will print the outputs below to help. ***/
if($stmt->execute($streetch)) { /*** IT SEEMS TO HANG HERE AND NEVER MAKE IT TO THE RETURN STATEMENT WHICH IS FOR THE PURPOSES OF EXITING THE INSTANCE OF THE CLASS TO SEND A RESPONSE ***/
return 3;
}
else {
return 2;
}
这里是 echo 语句的输出,完全按照它出现的顺序 - 我将解释我在做什么(我隐藏了这些值,但它们看起来都是我想要的......我主要是想知道格式问题...如果我的格式有误,会破坏我对mysql 的POST 请求:
/*** THIS LINE IS RESPONSIBLE FOR CREATING MY QUERY: $this->hh = $this->makeathing($this->stforquee, $this->querystring); Output below: ***/
INSERT INTO users(username,email,userfirst,userlast,updatedtime,usergender,fbverified,timezone,fbprofilelink,fblocale,fbid) VALUES(:username,:email,:userfirst,:userlast,:updatedtime,:usergender,:fbverified,:timezone,:fbprofilelink,:fblocale,:fbid)
/*** THIS IS WHAT A JSON OBJECT LOOKS LIKE OF THE ARRAY THAT I AM PASSING TO THE execute() FUNCTION - created by the line: echo "\n\n\n\n\n".json_encode($streetch)."\n\n\n\n\n\n"; Ouput below: ***/
{":username":"Eamon White",":email":"eamon.white7@gmail.com",":userfirst":"Eamon",":userlast":"White",":updatedtime":"2014-06-15T17:34:06+0000",":usergender":"male",":fbverified":"NO",":timezone":"-5",":fbprofilelink":"https:\/\/www.facebook.com\/app_scoped_user_id\/891510963470\/",":fblocale":"en_US",":fbid":"891510963470"}
所有这一切中最烦人的部分...希望对任何可以提供帮助的人最有说服力...所有信息都以完全可接受的方式成功存储在数据库中...只是程序似乎从未出现过想要移动到return 之后的execute()s 语句,这样我就可以在应用程序端得到处理的响应。任何帮助将不胜感激。总结问题 - 不能通过该死的$stmt->execute() 声明:)。
【问题讨论】: