将数据库的查询成果序列化成json格局
添加时间:2013-7-22 点击量:
<?php
class link_mysql{
private ¥host,¥uid,¥pwd,¥db,¥link,¥res;
function link_mysql(¥_host,¥_uid,¥_pwd,¥_db){
¥this->host = ¥_host;
¥this->uid = ¥_uid;
¥this->pwd = ¥_pwd;
¥this->db = ¥_db;
¥this->link = mysql_connect(¥this->host,¥this->uid,¥this->pwd);
mysql__db(¥this->db,¥this->link);
}
function exec_sql(¥sql){
//if you use sentence,then you must open your link;
¥res = mysql_query(¥sql);
return ¥res;
}
}
¥obj_link = new link_mysql(localhost,,,website);
¥res = ¥obj_link->exec_sql( userinfo);
¥str = [;
while(¥rows = mysql_fetch_assoc(¥res)){
¥str = ¥str.{name:¥rows[name],password:¥rows[password],age:¥rows[age]},;
}
¥str = rtrim(¥str,,) .];
echo ¥str;
?>
我俩之间有着强烈的吸引力。短短几个小时后,我俩已经明白:我们的心是一个整体的两半,我俩的心灵是孪生兄妹,是知己。她让我感到更有活力,更完美,更幸福。即使她不在我身边,我依然还是感到幸福,因为她总是以这样或者那样的方式出现在我心头。——恩里克·巴里奥斯《爱的文明》
<?php
class link_mysql{
private ¥host,¥uid,¥pwd,¥db,¥link,¥res;
function link_mysql(¥_host,¥_uid,¥_pwd,¥_db){
¥this->host = ¥_host;
¥this->uid = ¥_uid;
¥this->pwd = ¥_pwd;
¥this->db = ¥_db;
¥this->link = mysql_connect(¥this->host,¥this->uid,¥this->pwd);
mysql__db(¥this->db,¥this->link);
}
function exec_sql(¥sql){
//if you use sentence,then you must open your link;
¥res = mysql_query(¥sql);
return ¥res;
}
}
¥obj_link = new link_mysql(localhost,,,website);
¥res = ¥obj_link->exec_sql( userinfo);
¥str = [;
while(¥rows = mysql_fetch_assoc(¥res)){
¥str = ¥str.{name:¥rows[name],password:¥rows[password],age:¥rows[age]},;
}
¥str = rtrim(¥str,,) .];
echo ¥str;
?>