From 4a590e1837484d5d79279ecb1955dcc1e5ceeedb Mon Sep 17 00:00:00 2001 From: Matthias Gilch Date: Thu, 14 Apr 2016 23:03:50 +0200 Subject: [PATCH 1/4] Moved old files in MySQL directory --- Db.php => MySQL/Db.php | 0 config.ini => MySQL/config.ini | 0 db_functions.php => MySQL/db_functions.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Db.php => MySQL/Db.php (100%) rename config.ini => MySQL/config.ini (100%) rename db_functions.php => MySQL/db_functions.php (100%) diff --git a/Db.php b/MySQL/Db.php similarity index 100% rename from Db.php rename to MySQL/Db.php diff --git a/config.ini b/MySQL/config.ini similarity index 100% rename from config.ini rename to MySQL/config.ini diff --git a/db_functions.php b/MySQL/db_functions.php similarity index 100% rename from db_functions.php rename to MySQL/db_functions.php From ffaf7951b1b507a97c8eb0adadc16a03c77c264c Mon Sep 17 00:00:00 2001 From: Matthias Gilch Date: Thu, 14 Apr 2016 23:49:15 +0200 Subject: [PATCH 2/4] Created class Db The class have all the features from the MySQL example. I've tried also not to change much of the behaviour. --- SQLite3/Db.php | 101 +++++++++++++++++++++++++++++++++++++++++++++ SQLite3/config.ini | 3 ++ 2 files changed, 104 insertions(+) create mode 100644 SQLite3/Db.php create mode 100644 SQLite3/config.ini diff --git a/SQLite3/Db.php b/SQLite3/Db.php new file mode 100644 index 0000000..0f53b15 --- /dev/null +++ b/SQLite3/Db.php @@ -0,0 +1,101 @@ + connect(); + + // Check if valid connection + if( $connection === false ) { + return false; + } + + // Query the database + $result = $connection -> query( $query ); + + return $result; + } + + /** + * Fetch rows from the database (SELECT query) + * + * @param $query The query string + * @return bool False on failure / array Database rows on success + */ + public function select( $query ) { + $rows = array(); + $result = $this -> query( $query ); + + if( $result === false ) { + return false; + } + + while( $row = $result -> fetchArray() ) { + $rows[] = $row; + } + + return $rows; + } + + /** + * Fetch the last error from the database + * + * @return string Database error message + */ + public function error() { + $connection = $this -> connect(); + return $connection -> lastErrorMsg(); + } + + /** + * Quote and escape value for use in a database query + * + * @param string $value The value to be quoted and escaped + * @return string The quoted and escaped string + */ + public function quote( $value ) { + $connection = $this -> connect(); + $escaped = $connection -> escapeString( $value ); + return "'" . $escaped . "'"; + } +} diff --git a/SQLite3/config.ini b/SQLite3/config.ini new file mode 100644 index 0000000..acc5154 --- /dev/null +++ b/SQLite3/config.ini @@ -0,0 +1,3 @@ +[database] +database = test +encryption = thisisapassword From 2330bd74710bdb78d907bfd3061db81f94004578 Mon Sep 17 00:00:00 2001 From: Matthias Gilch Date: Fri, 15 Apr 2016 00:10:14 +0200 Subject: [PATCH 3/4] Added db_functions for SQLite3 --- SQLite3/db_functions.php | 95 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 SQLite3/db_functions.php diff --git a/SQLite3/db_functions.php b/SQLite3/db_functions.php new file mode 100644 index 0000000..b8f3dd7 --- /dev/null +++ b/SQLite3/db_functions.php @@ -0,0 +1,95 @@ + query( $query ); + + return $result; +} + +/** + * Fetch rows from the database (SELECT query) + * + * @param $query The query string + * @return bool False on failure / array Database rows on success + */ +function db_select($query) { + $rows = array(); + $result = db_query( $query ); + + if( $result === false ) { + return false; + } + + while( $row = $result -> fetchArray() ) { + $rows[] = $row; + } + + return $rows; +} + +/** + * Fetch the last error from the database + * + * @return string Database error message + */ +function db_error() { + $connection = db_connect(); + return $connection -> lastErrorMsg(); +} + +/** + * Quote and escape value for use in a database query + * + * @param string $value The value to be quoted and escaped + * @return string The quoted and escaped string + */ +function db_quote( $value ) { + $connection = db_connect(); + $escaped = $connection -> escapeString( $value ); + return "'" . $escaped . "'"; +} From bf37f3c7e561a10e4a9e8c1c1baae2b4a93d3b5c Mon Sep 17 00:00:00 2001 From: Matthias Gilch Date: Fri, 15 Apr 2016 00:13:33 +0200 Subject: [PATCH 4/4] Added README --- SQLite3/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 SQLite3/README.md diff --git a/SQLite3/README.md b/SQLite3/README.md new file mode 100644 index 0000000..5aae7de --- /dev/null +++ b/SQLite3/README.md @@ -0,0 +1,3 @@ +This is a SQLite3 version of the original MySQL database tutorial. + +The usage should be mostly the same