文件名称:txtSQL 文本数据库类
文件大小:92KB
文件格式:ZIP
更新时间:2012-05-19 14:08:15
txtSQL 文本数据库类 文本 TXT PHP
TXTSQL是一种文本数据库,文件存储方式类似mysql,兼容部分sql语句.
PHP需4.0以上版本才能运行。
官方网站:http://txtsql.com/
txtSQL简单例子(来源:http://smvcn.xhblog.com/archives/2007/259845.shtml)
connect('root', 'bar');
/*创建数据库
$sql->createdb(array('db' => 'demo')) or die('Error creating txtSQL DB, txtSQL said: '.$sql->get_last_error());
*/
/*选择数据库*/
$sql->selectdb ( 'demo' );
/*创建表
$columns = array('id' => array('type' => 'int', 'auto_increment' => 1, 'permanent' => 1 ),
'name' => array('type' => 'string', 'max' => 50),
'email' => array('type' => 'string', 'max' => 50)
);
foreach($columns as $k => $v){
echo "\$colums[$k]=";
foreach($v as $k1 => $v1){
echo "$k1:$v1 ";
}
echo "
";
}
$sql->execute('create table',array(
'table' => 'table1',
'columns' => $columns)) or die('建表发生错误:'.$sql->get_last_error());
if($sql->table_exists('table1','demo')){
echo "建表成功";
}else{
echo "建表失败";
}
*/
/*插入纪录
$value = array(0 => array('name' => 'abc','email' => 'abc@123.com'),
1 => array('name' => '123','email' => '123@bac.com'),
2 => array('name' => 'df','email' => 'reg@bac.com'),
3 => array('name' => 'trt','email' => 'hgh@bac.com'),
4 => array('name' => 'tyty','email' => 'ytyt@bac.com')
);
for($i=0;$i<5;$i++){
echo "\$value[$i]:";
foreach($value[$i] as $k => $v){
echo "[$k]=$v ";
}
echo "
";
}
for($i=0;$i<5;$i++){
if(!$sql->execute('insert',array('table' => 'table1','values' => $value[$i] ))){
die('An error occurred, txtSQL said: '.$sql->get_last_error());
}else{
echo "插入成功
";
}
}
*/
/*修改表数据
$value = array('name' => 'abc','email' => 'aaa@123.com');
if(!$sql->execute('update',array('table' => 'table1','where' => array('id = 1'),'values' => $value))){
die('An error occurred, txtSQL said: '.$sql->get_last_error());
}else{
echo "修改成功";
}
*/
/*删除表内容
$delete = array('table' => 'table1','where' => array('id > 1'));
$delcount = $sql->execute('delete',$delete);
echo $delcount;
*/
/*显示表内容*/
$select = array('table' => 'table1','orderby' => array('id','asc')/*,'where' => array('email =~ %bac%'),'limit' => array(0,9)*/);
$data = $sql->execute('select',$select);
echo "
id | name | |
---|---|---|
$v | "; } echo "
"; /*加入主键 $sql->execute('alter table',array('table' => 'table1','action' => 'addkey','name' => 'id','values' => array('name' => 'id'))); */ echo "最后插入ID号:".$sql->last_insert_id('table1') ; $sql->disconnect(); ?>
【文件预览】:
txtsql
----txtSQL.core.php(62KB)
----examples()
--------smNews()
--------txtSQLAdmin()
----data()
--------txtsql()
----txtSQL.class.php(41KB)