ios - 我想将我的 mySQL 数据库连接到我的 xcode 项目

标签 ios mysql iphone database xcode

<分区>

我正在尝试将我的 mysql 数据库连接到我的 xcode 项目,以获得一个简单的登录 View ,用户可以在其中输入他们的用户名和密码。我已经设置了数据库,但我需要使用 JSON 还是?

 <?php

 // Create connection
   $con=mysqli_connect("localhost","username","password","dbname");



 // Check connection
 if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

 // This SQL statement selects ALL from the table 'Locations'
 $sql = "SELECT * FROM Locations";

 // Check if there are results
 if ($result = mysqli_query($con, $sql))
 {
 // If so, then create a results array and a temporary one
 // to hold the data
 $resultArray = array();
 $tempArray = array();

 // Loop through each row in the result set
 while($row = $result->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 connections
 mysqli_close($con);
 ?>

最佳答案

这是一篇关于此的好文章:

[1]: http://codewithchris.com/iphone-app-connect-to-mysql-database/#parsejson Xcode JSON

我没有花太多时间在 xcode 上,但据我所知,没有用于连接到 MySQL 数据库的本地 API/框架(以及大多数其他同类框架)。所以是的 - 您需要使用数据库设置网站/服务器,该数据库具有生成 JSON 代码的网页。然后让 xcode 向服务器/网页发送 Web 请求,将 JSON 代码存储在变量中,然后使用 xcode 必须使用/操作 JSON 数据的任何方法。您需要确保 xcode 和 Web 服务器都不会阻止彼此以适当的安全权限传递数据。

您也可以将数据以您想要的任何格式传递到您的 xcode 应用程序 - JSON、CSV 甚至 XML。 xcode 具有的任何功能都是您应该坚持的。真的,您甚至可以构建自己的数据格式……这是您的应用程序,用它做您想做的事,在 xcode 中最容易使用的任何东西。

关于ios - 我想将我的 mySQL 数据库连接到我的 xcode 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43385058/

相关文章:

ios - UIViewController 生命周期

iphone - 带有图像的自定义工具栏

android - codenameone 和 Opentok native 接口(interface)

php - 包含 AND 子字符串条件的 WHERE 子句

mysql - 插入时触发 SQL 更新

iphone - UIViewContentModeScaleAspectFit 不适用于 UIScrollView subview UIImageView

ios - ScrollView 中的 WKWebView

mysql - 如何使用组连接获取第三个表计数

iphone - OpenGL ES 2.具有3个相邻点参数的着色器生成2个点?

ios - 如何让 UILabel 显示轮廓文本?