txtSQL簡單例子

2021-06-16 10:28:08 字數 2372 閱讀 8486

這幾天為了文庫的事情在學txtsql,這款開源的文字資料庫確實功能很強大。雖然還欠缺一些功能,不過也已經足夠用了。一邊看幫助手冊一邊寫了一些簡單的例子,等什麼時候有空翻譯一下他的幫助手冊好了(裡面還有一些錯誤需要修訂)

<?php

include('./txtsql.class.php');

$sql = new txtsql('./data');

$sql->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 "

"; }

$sql->execute('create table',array(

'table' => 'table1',

'columns' => $columns)) or die('建表發生錯誤:'.$sql->get_last_error());

if($sql->table_exists('table1','demo'))else

*//*插入紀錄

$value = array(0 => array('name' => 'abc','email' => '[email protected]'),

1 => array('name' => '123','email' => '[email protected]'),

2 => array('name' => 'df','email' => '[email protected]'),

3 => array('name' => 'trt','email' => '[email protected]'),

4 => array('name' => 'tyty','email' => '[email protected]')

);for($i=0;$i<5;$i++)

echo "

"; }

for($i=0;$i<5;$i++)else

} */

/*修改表資料

$value = array('name' => 'abc','email' => '[email protected]');

if(!$sql->execute('update',array('table' => 'table1','where' => array('id = 1'),'values' => $value)))else

*//*刪除表內容

$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

email

"; foreach ( $data as $key => $row )

echo "";

} echo "";

echo "表內共有 ".$sql->table_count('table1')." 行";

/*加入主鍵

$sql->execute('alter table',array('table' => 'table1','action' => 'addkey','name' => 'id','values' => array('name' => 'id')));

*/ echo "最後插入id號:".$sql->last_insert_id('table1') ;

$sql->disconnect();

?>

demo

簡單委託例子

例子1 using system using system.collections.generic using system.text 例子2 using system using system.collections.generic using system.text namespace 介面 c...

Pro C 簡單例子

include exec sql begin declare section char userid 11 hr oracle char std name 10 int std number int dept number exec sql end declare section char temp...

TabLayout簡單例子

要生成乙個tab ui需要用到兩個類,乙個是tabhost,乙個是tabwidget.tabwidget是用來顯示標籤欄的,內嵌在tabhost裡面。首先建立以tabhost為根節點的xml布局檔案 生成三個對應於標籤內容的activity pictureactivity public class ...