4、按SQL语句输出JSON格式
最近更新时间:2026-01-11 1:14:28
| 按SQL语句输出JSON格式程序编写例子 |
| 程序代码编写 |
| 存放目录格式: |
| 插件程序存放目录用: |
/e/extend/jsonsql/ |
|
|
| 所需程序文件: |
| /e/extend/jsonsql/index.php |
主程序文件 |
|
|
|
|
主程序文件内容(/e/extend/jsonsql/index.php):
<?php
require('../../class/connect.php'); //引入数据库配置文件和公共函数文件
require('../../data/dbcache/class.php'); //引入栏目缓存文件
$link=db_connect(); //连接数据库
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次//查询SQL语句
$eapi_query="select id,classid,title from {$dbtbpre}ecms_news order by newstime desc limit 5";
//JSON
$eapi_jsondbr=eapi_JsonDbQuery($eapi_query);
$eapi_jsonstr=eapi_JsonEn($eapi_jsondbr);
echo $eapi_jsonstr;
db_close(); //关闭数据库链接
$empire=null; //注消操作类变量
?> |
|
|
| 访问“按SQL语句输出JSON格式”插件文件主程序:/e/extend/jsonsql/index.php |
{
"0":{"id":"5","classid":"2","title":"增加信息5"},
"1":{"id":"4","classid":"2","title":"增加信息4"},
"2":{"id":"3","classid":"3","title":"增加信息3"},
"3":{"id":"2","classid":"3","title":"增加信息2"},
"4":{"id":"1","classid":"2","title":"增加信息1"}
} |
|