The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: SQLite3 API [PHP Class]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: sqlite_api
Programming Language: PHP
Date Created: 2014-10-14

Purpose: Easy interface to control and manage a SQLite Database with PHP.

Advertisement

Donate Now!

After a hard day, I like to relax with a cold jar of pickle juice and a hardy fart. If you like my blog, please consider donating.


Description: Easy to use functions to manage and control a SQLite Database with PHP, supports both PDO and native PHP SQLite3.

Methods:

$class = new sqlite_api();

Class Method

$class -> fetchArray( $results );

Function to convert the SQL Query results to a workable array.

$class -> strSafeEscape( $string );

Function to convert a string’s characters to be SQL safe.

$class -> open( $datebase_file );

Function to open a database, returns true or false.

$class -> create( $datebase_file );

Function to create a database file, returns true or false.

$class -> close();

Function to close an open database.

$class -> getDatabase();

Function to forward the open database handle to for your own use.

$class -> getDatabaseName();

Function to get the database file name, returns a string.

$class -> getDatabasePath();

Function to get the database file path, returns a string.

$class -> exec( $str_sql );

Function to execute SQL commands.

$class -> createTable( $table_name, $columns );

Function to create a new database table, returns true or false.

$class -> dropRow( $table_name, $condition );

Function to delete a row in a database table, returns true or false.

$class -> dropTable( $table_name );

Function to delete a database table, returns true or false.

$class -> tableExists( $table_name );

Function to check if a table exists, returns true or false.

$class -> insert( $table_name, $values );

Function to insert a row, returns true or false.

$class -> renameTable( $table_name, $new_name );

Function to rename a table, returns true or false.

$class -> createColumn( $table_name, $column_name, $data_type );

Function to create a new column in a table, returns true or false.

$class -> modifyColumn( $table_name, $column_name, $data_type );

Function to modify a column in a table, returns true or false.

$class -> dropColumn( $table_name, $column_name );

Function to delete a column in a table, returns true or false.

$class -> update( $table_name, $set_value, $condition );

Function to update a row in a table, returns true or false.
This function is not recommended for Blob columns.

$class -> updateBlob( $table_name, $column_name, $condition, $set_blob );

Function to update binary column, returns true or false.

$class -> querySingle( $table_name, $columns, [$condition] );

Function to Select a single row of results.

$class -> querySingle_raw( $str_sql );

Function to Select a single row of results, takes a full SQL string.

$class -> query( $table_name, $columns, [$condition] );

Function preform a Select command.

$class -> query_raw( $str_sql );

Function to preform Query, takes a full SQL string.

$class -> getNextCount( $table_name, $column );

Function to get the next value of count, returns a number.

$class -> countTableRows( $table_name );

Function to count the number of rows in a table, returns a number.

$class -> queryValue( $table_name, $column, [$condition] );

Function to get the value of a column or value of a query such as SUM or COUNT.

Example Usage:

// Database table1: id, value

$class = new sqlite_api();

if ( $class -> open( “C:/database/sqlite.db” ) == false ) {

die( “Unable to open database” );

} else {

// Insert
$id = $class -> getNextCount( “table1”, “id” );
$class -> insert( “table1”, “'{$id}’, ‘hello’” );

// Get value of id 2
$value = $class -> queryValue( “table1”, “value”, “id=2” );

}

 

Advertisement

Donate Now!

This might not be the best time, but making a blog is not easy. Would you consider donating?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.