我已经在这个工作了大约两天了。我正在尝试为我正在测试的iOS移动应用程序设置PHP后端,并且我已经获得了我正在尝试使用mysqli
的基本版本,但我想使用{{1相反。
我正在尝试将我从应用程序发送的用户信息存储到测试服务器(在我的计算机上)。到目前为止,我已经找到PDO
和UPDATE
与SELECT
- 但是当我到达我的应用程序发出PDO
请求以存储信息的步骤时POST
数据库,会发生什么如下:
a。)在我将参数作为参数数组绑定到mysql
函数后,它会一直到$stmt->execute()
行,或者我使用execute()
来在尝试bindValue
之前,在foreach
循环中单独绑定它们。如果我的代码进入未找到新用户的部分并尝试输入信息,则会发生以下情况:
execute()
这是echo语句的输出完全按照它出现的顺序 - 我会解释我在做什么(我隐藏了值但是它们看起来都是我想要的......我主要是想知道格式化问题...如果我格式化错误导致我的 $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;
}
请求被POST
打破:
mysql
关于所有这一切最令人讨厌的部分...并且希望对任何可以提供帮助的人最有说服力...所有信息都以完全可接受的方式成功存储在数据库中...这只是程序似乎永远不会想要在/*** 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()
陈述:)。
答案 0 :(得分:0)
请在以下属性中添加您的连接: $ db-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);
是否会输出一些错误?
答案 1 :(得分:0)
是的...我是半新手 - 足够有趣......我在我的代码中使用这些方法进行回复:
function getStatusCodeMessage($status)
{
// these could be stored in a .ini file and loaded
// via parse_ini_file()... however, this will suffice
// for an example
$codes = Array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => '(Unused)',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);
return (isset($codes[$status])) ? $codes[$status] : '';
}
// Helper method to send a HTTP response code/message
function sendResponse($status=null, $body = '', $content_type = 'text/html')
{
$status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
header($status_header);
header('Content-type: ' . $content_type);
print $body;
}
我使用100
响应只是为了使用不同的东西,所以我可以从我的应用程序中解决服务器端发生的事情 - 100
响应代表"继续&#34 ; - 正如您在数字定义中所见。我认为这实际上非常相关......但直到现在我还不知道它会 - 我只是在我的localhost上测试。好奇为什么重要,但它解决了我的问题。