swift开发之网络数据库(mysql)的增删改查(1)--URL传值
2015-02-04 15:33
489 查看
php部分:
<?php
@mysql_connect("localhost:3306","root","")or die("mysql连接失败");//连接数据库
@mysql_select_db("test")or die("db连接失败");//选择数据库
mysql_query("set names 'utf8'");//设置编码格式
class swiftConnApi{
public $id,$name,$bin,$price,$cont,$pwd;
//构造方法
public function __construct() {
$num = $_GET['id'];
$pwd = $_GET['pwd'];
$result = mysql_query("SELECT * FROM cs where id = $num");
while($row = mysql_fetch_array($result)){
if ($pwd==$row['pwd']) {
$this->id = $row['id'];
$this->pwd = $row['pwd'];
$this->name = $row['name'];
$this->bin = $row['bin'];
$this->price = $row['price'];
$this->cont = $row['cont'];
}else{
echo "密码不正确";
}
}
}
}
$myAd = new swiftConnApi();
echo json_encode($myAd);//转成json格式
?>
swift部分:
var strUrl = "http:192.168.1.102/swiftconnapi.php?id=1&pwd=123"
var url = NSURL(string: strUrl)
//获取数据
var data = NSData(contentsOfURL: url!, options: NSDataReadingOptions(), error: nil)
var json: AnyObject? = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments, error: nil)
var name : AnyObject? = json?.objectForKey("name")
欢迎转载,转载请注明出处http://blog.csdn.net/colinasd
<?php
@mysql_connect("localhost:3306","root","")or die("mysql连接失败");//连接数据库
@mysql_select_db("test")or die("db连接失败");//选择数据库
mysql_query("set names 'utf8'");//设置编码格式
class swiftConnApi{
public $id,$name,$bin,$price,$cont,$pwd;
//构造方法
public function __construct() {
$num = $_GET['id'];
$pwd = $_GET['pwd'];
$result = mysql_query("SELECT * FROM cs where id = $num");
while($row = mysql_fetch_array($result)){
if ($pwd==$row['pwd']) {
$this->id = $row['id'];
$this->pwd = $row['pwd'];
$this->name = $row['name'];
$this->bin = $row['bin'];
$this->price = $row['price'];
$this->cont = $row['cont'];
}else{
echo "密码不正确";
}
}
}
}
$myAd = new swiftConnApi();
echo json_encode($myAd);//转成json格式
?>
swift部分:
var strUrl = "http:192.168.1.102/swiftconnapi.php?id=1&pwd=123"
var url = NSURL(string: strUrl)
//获取数据
var data = NSData(contentsOfURL: url!, options: NSDataReadingOptions(), error: nil)
var json: AnyObject? = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments, error: nil)
var name : AnyObject? = json?.objectForKey("name")
欢迎转载,转载请注明出处http://blog.csdn.net/colinasd
相关文章推荐
- swift开发之网络数据库(mysql)的增删改查(2)--引用Alamofire的post传值
- ios开发-数据库网络之用php对mysql的增删改查(6)
- iOS开发 -- 数据库(增删改查)
- 数据库开发基础-★SQl Server 控制数据库的服务+数据库的创建与管理(增删改查)★
- [置顶] Android,java,php开发最基本的知识,mysql sqlite数据库的增删改查代理,sql语句
- ios开发-数据库网络之mysql创建数据库,表,基本SQL语句(5)
- 简单数据库mysql的增删改查(新手)
- pymysql 连接 Mysql 数据库及 简单的增删改查操作
- ios开发-数据库网络之mysql安装 删除 修改密码(4)
- tomcat+mysql+eclipse 开发的第一个例子:对数据库进行增删查改
- node 链接mysql 数据库及增删改查操作
- python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
- Visual C# 2008+SQL Server 2005 数据库与网络开发-- 1.2 .NET Framework 3.5介绍
- Visual C# 2008+SQL Server 2005 数据库与网络开发――2.4.2 数组
- Visual C# 2008+SQL Server 2005 数据库与网络开发――2.3.1 选择语句
- Visual C# 2008+SQL Server 2005 数据库与网络开发―― 2.6 创建项目
- Visual C# 2008+SQL Server 2005 数据库与网络开发―― 2.5错误和异常处理
- Visual C# 2008+SQL Server 2005 数据库与网络开发――2.1.2 类
- Visual C# 2008+SQL Server 2005 数据库与网络开发――3.1.2 C# 2005和2008之间的关系
- Visual C# 2008+SQL Server 2005 数据库与网络开发――2.2.2 运算符