我正在使用从Codeigniter到python的httppost请求,并将一个元组从MySQL返回到python
Codeigniter控制器:
$data['email'] = $this->input->post("email");
$url = 'http://domain/path';
$data = array('email' => $data['email']);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
Python代码:
elif self.path=="/forgotpass":
print "forgot password module"
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
self.send_response(200)
self.send_header('Content-type','text/html')
self.send_header("Access-Control-Allow-Origin","http://domain")
self.end_headers()
#print form['email'].value
email = str(form["email"].value)
sql = "SELECT email_address, personal_id from personal_info where email_address='"+email+"'"
result = validate(sql)
print result
#print email;
self.wfile.write(result)
def validate(sql):
try:
db = MySQLdb.connect("localhost","root","password","schema" )
cnn = db.cursor()
cnn.execute(sql)
return cnn.fetchone()
cnn.close()
except MySQLdb, e:
print "Error validate function"
显示是,我想现在是字符串格式。你知道吗
string(36) "('jerahmeel.acebuche@smsgt.com', 2L)"
在一个简单的代码点火器连接到一个模型。你知道吗
mysql数组的结果是:
数组(列=>;值)等。。你知道吗
您可以使用foreach和$item->;data;显示该数组
但是这个结果来自python,python是一个元组,将它返回给PHP是另一种方法。你知道吗
如何在PHP中打破这个元组?或者我应该在python上中断它并将其返回PHP?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐