我似乎无法弄清楚我的 mysqli 多查询出了什么问题。当我运行它时,我在 php 端没有收到任何错误,但在 Xcode 中我收到了一个致命错误并且它崩溃了。这是我在 php 端用来执行 mysqli 多查询的代码:
$sql2 = "SELECT * FROM database.database WHERE SenderID='" . $userUsername . "'; ";
$sql2 .= "SELECT * FROM database.database WHERE Username='" . $userUsername . "'; ";
$sql2 .= "SELECT * FROM database.database WHERE SenderID='" . $userUsername . "'; ";
// Execute multi query
if (mysqli_multi_query($conn,$sql2))
{
do
{
// Store first result set
if ($result2=mysqli_store_result($conn)) {
// Fetch one and one row
while ($row=mysqli_fetch_row($result2))
{
$activity[] = $row;
}
// Free result set
mysqli_free_result($result2);
}
}
while (mysqli_next_result($conn));
}
就像我之前说的那样,我没有从这个脚本中得到任何错误消息,但是在 Xcode 中,我在这段代码中得到了一个错误:
func retrieveActivity(latestMessage:String) {
self.caseLoadBool = false
let request = NSMutableURLRequest(URL: NSURL(string: "http://website/info.php")!)
request.HTTPMethod = "POST"
let postString = "string=\(self.userUsername)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)", terminator: "")
return
}
// Convert the json data into an array
/* ERROR ON THIS LINE */ let dataArray:[AnyObject] = (try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as! [AnyObject]
我不确定我做错了什么,同样的 Xcode 代码在处理其他单个 mysqli 查询时对我有用,我不确定这是一个 mysqi 多查询这一事实是否与它有关。任何帮助或建议将不胜感激!谢谢!
更新:错误代码:致命错误:“尝试!” 表达式意外引发错误:Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.}:文件 /Library/Caches/com.apple.xbs/Sources/swiftlang_PONDEROSA/swiftlang_PONDEROSA-700.1.101.6/src/swift/stdlib/public/core/ErrorType.swift,第 50 行