通过IOS APP连接MySQL数据库的最佳解决方案(中)

2.5:如何编写一个PHP Web服务来查询数据库

先点击cPanel上的“文件管理器”进如下一个界面再点击publi_html左侧地球形状的图标进入文件管理:

通过IOS APP连接MySQL数据库的最佳解决方案(中)


通过IOS APP连接MySQL数据库的最佳解决方案(中)

点击球形图标后进入创建文件界面并点击文件左侧图标+进行创建一个文件:

通过IOS APP连接MySQL数据库的最佳解决方案(中)

此时命名文件名为:service.php 并添加以下代码于其中:

<code>fetch_object()) { // Add each row into our results array $tempArray = $row;     array_push($resultArray, $tempArray); }  // Finally, encode the array to JSON and output the results echo json_encode($resultArray);} // Close connectionsmysqli_close($con);?>/<code>

第三行 "username","password","dbname" 填入您相关的数据库信息及密码。

打开https://域名/service.php

即可看到我们插入数据库的相关信息!

2.6: 将数据库里的信息显示于IOS APP之上

在Mac上打开Xcode创建一个项目并确保使用Swift语言:

通过IOS APP连接MySQL数据库的最佳解决方案(中)

编辑Info.plist文件, “App Transport Security Settings”下添加 “Allow Arbitrary Loads”并设值为YES

通过IOS APP连接MySQL数据库的最佳解决方案(中)

storyboard设置View Controller并添加Table View于其中:

通过IOS APP连接MySQL数据库的最佳解决方案(中)



分享到:


相關文章: