douguluan5102 2015-06-04 19:33
浏览 68

从iOS应用程序中的QR扫描(文本)发送数据以存储在SQL数据库中

I have a QR scanner that will read the text that is embedded and I would like it to store the information into the SQL database. The database is setup, and the php site handles the input correctly if I enter manually into the URL (ex. www.blah.com/input.php?name=Bob). However, I cannot figure out how to get the information to submit to my php site and/or put the information into the database. I'm sure there is a better/easier way. Below is the code I am using:

NSString *url= [NSString stringWithFormat:@"http://blah.com/input.php?name=%@", name];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString: url]];

Then this is my current php setup:

<?php 
header('Content-type: text/plain; charset=utf-8');


$db_conn = new  PDO('mysql:host=host;dbname=db','user','pwd');
$db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$date = date("m/d/y");
$time = date("h:i:sa");
//$name = "";
$name = ($_GET['name']); 


$qry = $db_conn->prepare('INSERT INTO CheckIn(`date`,`time`,`name`) VALUES          (:date,:time,:name)');
$qry->bindParam(':date', $date);
$qry->bindParam(':time', $time);
$qry->bindParam(':name', $name);

$qry->execute();

if ($qry) { $message = "success"; }
else { $message = "failed"; }

echo utf8_encode($message);
?>
  • 写回答

1条回答 默认 最新

  • dsbc80836 2015-06-05 23:51
    关注

    You can use NSURLConnection class to send synchronous / asynchronous request.

    Here is an example for the synchronous request:

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"GET"];
    NSURLResponse *response;
    NSError *err;
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request
                                               returningResponse:&response 
                                                           error:&err];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器