Sqlite database connection class. Sqlite database connection class * sqlite database connection class uses php to connect to sqlite. Sqlite database tutorial connection class * sqlite database connection class is to use php to teach sqlite database connection class * sqlite database connection class is to use php to connect to sqlite.
*/
Class db_class {
Var $ conn = null;
Var $ querynum = 0;
/**
* Database connection. the database connection identifier is returned.
*
* @ Param string $ database server host
* @ Param string $ database server account
* @ Param string $ database server password
* @ Param string $ database name
* @ Param bool $ indicates whether to maintain a persistent connection. 1 indicates a persistent connection, and 0 indicates a non-persistent connection.
* @ Return link_identifier $ dbuser, $ dbpw, $ dbname,
*/
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;
}
/**
* Execute SQL statements
*
* @ Param string $ SQL statement
* @ Param string $ the default value is null. the optional value is cache unbuffered.
* @ Param int $ cache lifecycle in seconds
* @ Return resource
*/
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;
}
/*
* @ Param string $ table name
* @ Param string $ where condition
* @ Param string $ colum name
* @ Param string $ limit quantity
*/
Function getlist ($ table, $ wheres = "1 = 1", $ colums = '*', $ limits = '000000', $ orderbys = "id desc "){
$ Query = $ this-> query ("select ". $ colums. "from ". $ table. "where ". $ wheres. "order ". $ orderbys. "limit ". $ limits, $ type, $ expires, $ dbname );
While ($ rs = $ this-> fetch_array ($ query )){
$ Datas [] = $ rs;
}
// Print_r ("select". $ colums. "from". $ table. "where". $ wheres. "limit". $ limits );
// Print_r ($ rs); die ();
$ This-> free_result ($ query );
Return $ datas;
}
Function add_one ($ table, $ colums, $ data ){
// Die ("insert into". $ table. "(". $ colums. ") values (". $ data .")");
$ Query = $ this-> query ("insert ". $ table. "(". $ colums. ") values (". $ data. ")", $ type, $ expires, $ dbname );
// Return $ this-> insert_id ();
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;
}
// Update max_vote set maxtitle = '$ title', maxban =' $ ban ',
/**
* Execute the SQL statement and get only one record
*
* @ Param string $ SQL statement
* @ Param string $ the default value is null. the optional value is cache unbuffered.
* @ Param int $ cache lifecycle in seconds
* @ Return array
*/
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;
}
/**
* Get a row from the result set as an associated array
*
* @ Param resource $ database query result resource
* @ Param string $ defines the return type
* @ Return array
*/
Function fetch_array ($ query, $ result_type = sqlite_assoc ){
Return sqlite_fetch_array ($ query, $ result_type );
}
/**
* Obtain the number of rows affected by the previous sqlite operation.
*
* @ Return int
*/
Function affected_rows (){
Return sqlite_changes ($ this-> conn );
}
/**
* Number of rows in the result set
*
* @ Return int
*/
Function num_rows ($ query ){
Return sqlite_num_rows ($ query );
}
/**
* Number of fields in the returned result set
*
* @ Return int
*/
Function num_fields ($ query ){
Return sqlite_num_fields ($ query );
}
/**
*
* @ Return array backup, generally not required.
*/
Function result ($ query, $ row ){
Return @ sqlite_fetch_all ($ query, sqlite_assoc );
}
/**
* Sqlite does not have a function.
*/
Function free_result ($ query ){
Return;
}
/**
* Obtain the id generated by the previous insert operation.
*
* @ Return int
*/
Function insert_id (){
Return sqlite_last_insert_rowid ($ this-> connid );
}
/**
*
* @ Return array only obtains the numeric index.
*/
Function fetch_row ($ query ){
Return sqlite_fetch_array ($ query, sqlite_num );
}
/**
*/
Function fetch_assoc ($ query ){
Return $ this-> fetch_array ($ query, sqlite_assoc );
}
/**
*
* @ Return string
*/
Function version (){
Return sqlite_libversion ();
}
Function close (){
Return sqlite_close ($ this-> conn );
}
/**
*
* @ Return string
*/
Function error (){
Return sqlite_error_string ($ this-> errno );
}
/**
*
* @ Return int
*/
Function errno (){
Return sqlite_last_error ($ this-> conn );
}
/**
* Display the mysql tutorial error message
*/
Function halt ($ message = '', $ SQL = ''){
Exit ("sqlitequery: $ SQL
Sqliteerror: ". $ this-> error ()."
Sqliteerrno: ". $ this-> errno ()."
Message: $ message ");
}
}
?>
Http://www.bkjia.com/PHPjc/630796.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630796.htmlTechArticlesqlite database connection class * sqlite database connection class is the use of php and sqlite connection operations. Sqlite database tutorial connection class * sqlite database connection class is to use php to teach...