*/
lass db_class {
var
$conn
=null;
var
$querynum
= 0;
function
connect(
$dbhost
,
$pconnect
= 0) {
$error
= '';
$func
=
$pconnect
== 1 ? 'sqlite_popen' : 'sqlite_open';
if
(!
$this
-> conn =
$func
(
$dbhost
, 0666,
$error
)) {
$this
-> halt(
$error
);
}
return
$this
-> conn;
}
function
query(
$sql
,
$type
= '' ,
$expires
= 3600,
$dbname
= '') {
$error
= '';
$func
=
$type
== 'unbuffered' ? 'sqlite_unbuffered_query' : 'sqlite_query';
if
(preg_match(
"/^s*select/i"
,
$sql
)) {
$query
=
$func
(
$this
-> conn,
$sql
, sqlite_assoc,
$error
);
}
else
{
$query
= sqlite_exec(
$this
-> conn,
$sql
,
$error
);
}
if
(
$error
) {
$this
-> halt(
$error
,
$sql
);
}
$this
-> querynum++;
return
$query
;
}
function
getlist(
$table
,
$wheres
=
"1=1"
,
$colums
= '*' ,
$limits
= '3000',
$orderbys
=
"id desc"
) {
$query
=
$this
-> query(
"select "
.
$colums
.
" from "
.
$table
.
" where "
.
$wheres
.
" order by "
.
$orderbys
.
" limit "
.
$limits
,
$type
,
$expires
,
$dbname
);
while
(
$rs
=
$this
-> fetch_array(
$query
)){
$datas
[]=
$rs
;
}
$this
-> free_result(
$query
);
return
$datas
;
}
function
add_one(
$table
,
$colums
,
$data
) {
$query
=
$this
-> query(
"insert into "
.
$table
.
" ("
.
$colums
.
") values("
.
$data
.
")"
,
$type
,
$expires
,
$dbname
);
return
$query
;
}
function
delist(
$table
,
$idarray
,
$wheres
=
"no"
) {
if
(
$wheres
=='no')
$query
=
$this
-> query(
"delete from "
.
$table
.
" where id in("
.
$idarray
.
")"
,
$type
,
$expires
,
$dbname
);
else
$query
=
$this
-> query(
"delete from "
.
$table
.
" where "
.
$wheres
,
$type
,
$expires
,
$dbname
);
return
$query
;
}
function
updatelist(
$table
,
$updatedata
,
$idarray
) {
$query
=
$this
-> query(
"update "
.
$table
.
" set "
.
$updatedata
.
" where id in("
.
$idarray
.
")"
,
$type
,
$expires
,
$dbname
);
return
$query
;
}
function
get_one(
$sql
,
$type
= '',
$expires
= 3600,
$dbname
= '') {
$query
=
$this
-> query(
$sql
,
$type
,
$expires
,
$dbname
);
$rs
=
$this
-> fetch_array(
$query
);
$this
-> free_result(
$query
);
return
$rs
;
}
function
fetch_array(
$query
,
$result_type
= sqlite_assoc) {
return
sqlite_fetch_array(
$query
,
$result_type
);
}
function
affected_rows() {
return
sqlite_changes(
$this
-> conn);
}
function
num_rows(
$query
) {
return
sqlite_num_rows(
$query
);
}
function
num_fields(
$query
) {
return
sqlite_num_fields(
$query
);
}
function
result(
$query
,
$row
) {
return
@sqlite_fetch_all(
$query
, sqlite_assoc);
}
function
free_result(
$query
) {
return
;
}
function
insert_id() {
return
sqlite_last_insert_rowid(
$this
-> connid);
}
function
fetch_row(
$query
) {
return
sqlite_fetch_array(
$query
, sqlite_num);
}
function
fetch_assoc(
$query
) {
return
$this
-> fetch_array(
$query
, sqlite_assoc);
}
function
version() {
return
sqlite_libversion();
}
function
close() {
return
sqlite_close(
$this
-> conn);
}
function
error() {
return
sqlite_error_string(
$this
-> errno);
}
function
errno() {
return
sqlite_last_error(
$this
-> conn);
}
function
halt(
$message
= '',
$sql
= '') {
exit
(
"sqlitequery:$sql <br> sqliteerror:"
.
$this
-> error() .
" <br> sqliteerrno:"
.
$this
-> errno() .
" <br> message:$message"
);
}