开发文档

在开发插件或其它扩展时,需要用到ourphp的数据库操作类,来调用数据库中的数据。ourphp数据库操作语法要在php文件中使用,无法在html文件中使用。并且要引入数据库连接文件,具体如下:

一、开发插件

后台管理页面需引入 <?php include="../ourphp_plus_admin.php" ?>,前端需引入 <?php include="../ourphp_plus_index.php" ?>

二、其它页面使用

页面需引入 <?php include="./config/ourphp_code.php" ?> 和 <?php include="./config/ourphp_config.php" ?> 建议额外引入 <?php include="./function/ourphp_function.class.php" ?>

引入后可使用ourphp的数据库操作语法。

读取单条数据
<?php
$rs = $db -> select("id","ourphp_web","where id = 1"); //select("字段可以为*,多个字段用,隔开","表名","条件(可为空)")
echo $rs[0];
?>
读取列表数据
<?php
$list = $db -> listgo("id","ourphp_web","where id = 1 order by id desc"); //listgo("字段可以为*,多个字段用,隔开","表名","条件(可为空)")
while($rs = $db -> whilego($list)){
echo $rs[0];
}
?>
解析列表数据whilego
<?php
whilego($list,1) 第二个参数可不设,默认1(fetch_array),2(fetch_row),3(fetch_assoc)
while($rs = $db -> whilego($list,1)){
//这里写上业务逻辑,具体参考数据库文档
}
?>
插入数据方式一
<?php
$db -> insert("ourphp_web","`name` = '".$_POST['name']."',`tel` = '2'",""); //insert("表名","插入内容","条件(可为空)");
?>
插入数据方式二(一次插入多条)
<?php
组合记录:
$info = array(
"table" => "OP_Class,OP_Lang,OP_Title",
"data" => array(
array(13,"cn","插入测试"),
array(14,"cn","插入测试"),
array(15,"cn","插入测试"),
)
);
$db -> insertarray("ourphp_web",$info,""); //insertarray("表名","插入组合变量$info","条件(可为空)");
?>
获取插入记录ID
<?php
在$db -> insert或$db -> insertarray后面执行
$newid = $db -> insertid(); //可获取刚插入记录的ID
echo $newid;
?>
更新记录
<?php
$db -> update("ourphp_web","`name` = '".$_POST['name']."',`tel` = '2'","where id = 1"); //update("表名","插入更新内容","条件(可为空)");
?>
删除记录
<?php
$db -> del("ourphp_web","where id = 1"); //del("表名","条件");
?>
获取数据报错
<?php
$db -> error();
使用方法:$db -> select("*","ourphp_web","where id = 1") or die($db -> error());
?>
删除表
<?php
$db -> drop("ourphp_web"); //drop("要删除的表名");
?>
获取记录数
<?php
$db -> rows($list);
使用方法
$list = $db -> listgo("*","ourphp_web","order by desc");
$rows = $db -> rows($list);
echo $rows;
?>
填充表名
<?php
$db -> datatable("web"); //相当于 ourphp_web
使用方法
datatable会帮你省去输入ourphp_的烦恼,后期如果安装多个ourphp并且使用不同表名前缀的话datatable很有帮助。
$db -> select("*",$db->datatable("product"),"where id = 1"); //表示调用ourphp_product这个表
为什么要使用这个类?后期可能因为重多的开发者开发插件,插件依赖的数据库表可能有很多,所以datatable会提升开发速度。
?>
对插入的内容过滤(安全)
<?php
开发插件时在使用insert或update等插入数据时,对$_POST[]及$_GET[]要进行过滤
例:dowith_sql($_POST['name'])

在外部使用ourphp系统数据库操作类时,请引入 include = "./function/ourphp_function.class.php";
然后在过滤,例:dowith_sql($_POST['name'])

数字类型用intval()过滤,例:$db -> update("ourphp_web","`name` = '".dowith_sql($_POST['name'])."'","where id = ".intval($_GET['id']));
?>