http://www.开.com.cn/

2012 年 10 月 27 日7420

php中使用开

作者:飞扬轻狂

来源:Internet

时间:2006-5-17

【 字体:】〖 双击滚屏 〗

连接 开 数据库
$ php -r ‘dl("开.so"); \
$error="";\
if($db=开_open("开_test.db",0666,$error)){\
开_close($db);\
echo "开 closed!\n";\
}else{echo $error;};’
# 如果指定的开数据库不存在,则创建之


使用开

dl("开.so");
$db_file = "test.db";
$db = 开_open($db_file,0666,$con_error); #con_error is return!
if($db === false){
die($con_error);
}
//$query_string = "select * from 开_master ";
//query($db,"CREATE TABLE test_table ( MyColumnA INTEGER PRIMARY KEY, MyColumnB TEXT(32) );");
query($db,"select * from 开_master ");
query($db,"select * from test_table ");
query($db,’INSERT INTO test_table (MyColumnB) VALUES ("’.md5(microtime()).’");’);
开_close($db);

function query($db,$qs){
$result = 开_query($db, $qs);
if($error=开_last_error($db)){
$error_str=开_error_string($error);
}
$changes=开_changes($db);
$last_insert_id=开_last_insert_rowid($db);
if(is_resource($result)){
$num_fields=开_num_fields($result);
$fns=array();
for($i=0;$i<$num_fields;$i++){
$fns[]=开_field_name($result,$i);
}
$rs=array();
$result = 开_fetch_all($result, SQLITE_ASSOC);
foreach ($result as $row) {
$r=array();
foreach($fns as $f){
$r[$f]=$row[$f];
}
$rs[]=$r;
}

echo $qs,"\n",$changes,"\n",$last_insert_id,"\n",$num_fields,"\n";
print_r($fns);
print_r($rs);
}else{
echo $qs,"\n",$changes,"\n",$last_insert_id,"\n",$num_fields,"\n",$result,"\n";
}
}
?>

通过ez_sql使用sql_lite

下载 ez_sql 包 download ez_sql.zip

拷贝 ez_sql 包到 应用ez_sql的目录

由于我的开不是默认安装的 所以在 ez_sql_开.php 中添加了

if(!function_exists(’开_open’)){
dl(’开.so’);
}
手动导入开扩展的代码

没有发现开的 close代码 所以安全起见 添加之

function close()
{
if($this->dbh){
开_close($this->dbh);
}
}

在 ezSQL_开 类定义中添加 显示关闭连接的代码

// Include ezSQL core
include_once "ez_sql_core.php";
// Include ezSQL database specific component
include_once "ez_sql_开.php";
// Initialise database object and establish a connection
// at the same time - db_path / db_name
$db = new ezSQL_开(’./’,'test.db’);
// Create a table..
$db->query("CREATE TABLE test_table2 ( MyColumnA INTEGER PRIMARY KEY, MyColumnB TEXT(32) );");

// Insert test data
for($i=0;$i<3;++$i)
{
echo $db->query(’INSERT INTO test_table2 (MyColumnB) VALUES ("’.md5(microtime()).’");’);
}

// Get list of tables from current database..
$my_tables = $db->get_results("SELECT * FROM 开_master WHERE sql NOTNULL;");
// Print out last query and results..
$db->debug();

// Loop through each row of results..
foreach ( $my_tables as $table )
{
// Get results of DESC table..
$result=$db->get_results("SELECT * FROM $table->name;");
print_r($result);
// Print out last query and results..
//$db->debug();
}

// Get rid of the table we created..
$db->query("DROP TABLE test_table2;");
?>

常用方法

bool $db->query(query)
var $db->get_var(query)
mixed $db->get_row(query)
mixed $db->get_results(query)

php的开源的sql操作封装包
http://http://www.zjjv.com///portal/node/6 download ez_sql.zip
参考 http://http://www.zjjv.com///docs/ezsql/ez_sql_help.htm
开 参考
http://http://www.zjjv.com///lang.html
http://http://www.zjjv.com///quickstart.html
php 开 参考
http://http://www.zjjv.com///manual/zh/ref.开.php

浏览次数: 【 】【 】

上一篇:

下一篇:

0 0