PHP封装返回Ajax字符串和JSON数组
<?php
class DBDA
{
public $host="localhost";
public $uid = "root";
public $pwd = "123";
public $dbname = "mydb"; //成员方法
public function Query($sql,$type=1)
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$r = $db->query($sql); if($type==1)
{
return $r->fetch_all();
}
else
{
return $r;
}
} //返回字符串的方法
public function StrQuery($sql,$type=1)
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$r = $db->query($sql); if($type==1)
{
$attr = $r->fetch_all();
$str = "";
foreach($attr as $v)
{
$str .= implode("^",$v)."|";
} return substr($str,0,strlen($str)-1); }
else
{
return $r;
}
} //返回JSON
function JSONQuery($sql,$type=1)
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$r = $db->query($sql); if($type==1)
{
return json_encode($r->fetch_all(MYSQLI_ASSOC));
}
else
{
return $r;
}
}
}
PHP封装返回Ajax字符串和JSON数组的更多相关文章
- Java解析json字符串和json数组
Java解析json字符串和json数组 public static Map<String, String> getUploadTransactions(String json){ Map ...
- jsoncpp构造json字符串和json数组
jsoncpp构造json字符串和json数组 参考文章:Jsoncpp的简单使用 下载json文件夹放在c++项目的include目录下,在CMakeLists中include进去,然后就可以在代码 ...
- java代码中fastjson生成字符串和解析字符串的方法和javascript文件中字符串和json数组之间的转换方法
1.java代码中fastjson生成字符串和解析字符串的方法 List<TemplateFull> templateFulls = new ArrayList<TemplateFu ...
- js中字符串和json数组的相互转换
//示例 var a={"name":"tom","sex":"男","age":"24& ...
- Gson解析json字符串、json数组转换成对象
实体类: public class Product { private int id; private String name; private String date; public int get ...
- 封装返回给前台的json
JsonResult类的定义: /*生成Json串*/ public class JsonResult { /** * 返回错误状态的json串 * * @param status 错误代码,非零数值 ...
- 字符串转json数组
import net.sf.json.JSONArray;import net.sf.json.JSONObject; String content = inBankOdd.getContent(). ...
- android JSONArray JSONObject 字符串转json数组 遍历json对象
String json = "{''data'':[{''name'':''Wallace''},{''name'':''Grommit''}]}"; StringBuffer m ...
- 将json数组字符串转换为json数组对象(值是json对象的数组)
var str1 ='[{"name":"kevin","age":18},{"name":"rose&quo ...
随机推荐
- corethink功能模块探索开发(六)让这个模块在前台显示
效果图:(注意右上角) 实现模块的前台显示只需要在模块目录中的Controller目录建立IndexController.class.php,实现index方法.继承HomeController.就能 ...
- 【WEB HTTP】集成点:网关、隧道及中继
网关:网关可以作为某种翻译器使用,它抽象出了一种能够到达资源的方法.网关是资源与应用程序之间的粘合剂. 在不同http版本之间进行转换的Web代理和网关一样,他们会执行复杂的逻辑,以便在各个端点之间进 ...
- gitattributes手册
gitattributes(5) Manual Page 1.gitattributes是什么? gitattributes用于定义每个路径的属性. 其语法是:pattern attr1 attr2 ...
- iOS 52个技巧学习心得笔记 第二章 对象 , 消息, 运行期
1. 属性 在开发过程中经常要用到定义属性,@property和@synthesize是经常用到的属性, property在.h文件中作声明,@synthesize在.m文件中用于实现 // Stud ...
- 内核模块编译时怎样绕过insmod时的版本检查
1.Uboot:每个arm芯片或者海斯芯片都有各自的uboot. 2.但他们的内核版本可以是一样的,主要是跟各自内核的进行的编译选项有关, 31的内核版本里加了版本检查选项“Kernel type-& ...
- C语言math.h库函数中atan与atan2的区别
源: C语言math.h库函数中atan与atan2的区别 C语言中的atan和atan2
- java实现文件的压缩和解压
java实现文件的压缩和解压 代码压缩实现 package com.hjh.demo.zip; import java.io.BufferedInputStream; import java.io.F ...
- 20145210姚思羽《网络对抗》MSF基础应用实验
20145210姚思羽<网络对抗>MSF基础应用实验 实验后回答问题 1.用自己的话解释什么是exploit,payload,encode. exploit就是进行攻击的那一步 paylo ...
- 实现利用公钥私钥免密码登录Linux服务器
原理 客户端生成公钥私钥,把公钥拷贝给linux服务器,用自己的私钥连接服务器.实现如下: 如果是两台Linux服用器A和B,A来实现免密码登录B A执行ssh-keygen -t rsa 就会在/r ...
- 算法总结之 将单链表的每K个节点之间逆序
给定一个单链表的表头节点head,实现一个调整单链表的函数,是的每k个节点之间逆序,如果最后不够k个节点一组,则不调整最后几个节点 思路: 如果k的值小于2,不调整.k<1 没有意义,k==1代 ...