From 17eb8920f68acfa3705e5947cafa6eb842282545 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 30 Nov 2023 12:19:43 +0900 Subject: [PATCH 1/4] docs: add missing methods in Database Utility Class --- user_guide_src/source/database/utilities.rst | 78 +++++++++++++++++++ .../source/database/utilities/004.php | 9 +++ .../source/database/utilities/005.php | 7 ++ .../source/database/utilities/006.php | 7 ++ .../source/database/utilities/007.php | 7 ++ .../source/database/utilities/008.php | 9 +++ .../source/database/utilities/009.php | 8 ++ .../source/database/utilities/010.php | 12 +++ 8 files changed, 137 insertions(+) create mode 100644 user_guide_src/source/database/utilities/004.php create mode 100644 user_guide_src/source/database/utilities/005.php create mode 100644 user_guide_src/source/database/utilities/006.php create mode 100644 user_guide_src/source/database/utilities/007.php create mode 100644 user_guide_src/source/database/utilities/008.php create mode 100644 user_guide_src/source/database/utilities/009.php create mode 100644 user_guide_src/source/database/utilities/010.php diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index 8a094cfff549..eeb88cd1853d 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -30,6 +30,84 @@ parameter. Using the Database Utilities **************************** +Retrieve List of Database Names +================================ + +Returns an array of database names: + +.. literalinclude:: utilities/004.php + :lines: 2- + +Determine If a Database Exists +============================== + +Sometimes it's helpful to know whether a particular database exists. +Returns a boolean ``true``/``false``. Usage example: + +.. literalinclude:: utilities/005.php + :lines: 2- + +.. note:: Replace ``database_name`` with the name of the database you are + looking for. This method is case sensitive. + +Optimize a Table +================ + +Permits you to optimize a table using the table name specified in the +first parameter. Returns ``true``/``false`` based on success or failure: + +.. literalinclude:: utilities/006.php + :lines: 2- + +.. note:: Not all database platforms support table optimization. It is + mostly for use with MySQL. + +Repair a Table +============== + +Permits you to repair a table using the table name specified in the +first parameter. Returns ``true``/``false`` based on success or failure: + +.. literalinclude:: utilities/007.php + :lines: 2- + +.. note:: Not all database platforms support table repairs. + +Optimize a Database +=================== + +Permits you to optimize the database your DB class is currently +connected to. Returns an array containing the DB status messages or +``false`` on failure: + +.. literalinclude:: utilities/008.php + :lines: 2- + +.. note:: Not all database platforms support database optimization. It + it is mostly for use with MySQL. + +Export a Query Result as a CSV File +=================================== + +Permits you to generate a CSV file from a query result. The first +parameter of the method must contain the result object from your +query. Example: + +.. literalinclude:: utilities/009.php + :lines: 2- + +The second, third, and fourth parameters allow you to set the delimiter +newline, and enclosure characters respectively. By default commas are +used as the delimiter, ``"\n"`` is used as a new line, and a double-quote +is used as the enclosure. Example: + +.. literalinclude:: utilities/010.php + :lines: 2- + +.. important:: This method will NOT write the CSV file for you. It + simply creates the CSV layout. If you need to write the file + use the :php:func:`write_file()` helper. + Export a Query Result as an XML Document ======================================== diff --git a/user_guide_src/source/database/utilities/004.php b/user_guide_src/source/database/utilities/004.php new file mode 100644 index 000000000000..4a6b4f673859 --- /dev/null +++ b/user_guide_src/source/database/utilities/004.php @@ -0,0 +1,9 @@ +listDatabases(); + +foreach ($dbs as $db) { + echo $db; +} diff --git a/user_guide_src/source/database/utilities/005.php b/user_guide_src/source/database/utilities/005.php new file mode 100644 index 000000000000..77b0310708e5 --- /dev/null +++ b/user_guide_src/source/database/utilities/005.php @@ -0,0 +1,7 @@ +databaseExists('database_name')) { + // some code... +} diff --git a/user_guide_src/source/database/utilities/006.php b/user_guide_src/source/database/utilities/006.php new file mode 100644 index 000000000000..7fe39efdfdd8 --- /dev/null +++ b/user_guide_src/source/database/utilities/006.php @@ -0,0 +1,7 @@ +optimize_table('table_name')) { + echo 'Success!'; +} diff --git a/user_guide_src/source/database/utilities/007.php b/user_guide_src/source/database/utilities/007.php new file mode 100644 index 000000000000..603b69cc9342 --- /dev/null +++ b/user_guide_src/source/database/utilities/007.php @@ -0,0 +1,7 @@ +repairTable('table_name')) { + echo 'Success!'; +} diff --git a/user_guide_src/source/database/utilities/008.php b/user_guide_src/source/database/utilities/008.php new file mode 100644 index 000000000000..b5f19a33fd9e --- /dev/null +++ b/user_guide_src/source/database/utilities/008.php @@ -0,0 +1,9 @@ +optimizeDatabase(); + +if ($result !== false) { + print_r($result); +} diff --git a/user_guide_src/source/database/utilities/009.php b/user_guide_src/source/database/utilities/009.php new file mode 100644 index 000000000000..054d88afa95e --- /dev/null +++ b/user_guide_src/source/database/utilities/009.php @@ -0,0 +1,8 @@ +query('SELECT * FROM mytable'); + +echo $dbutil->getCSVFromResult($query); diff --git a/user_guide_src/source/database/utilities/010.php b/user_guide_src/source/database/utilities/010.php new file mode 100644 index 000000000000..c2b50a17360f --- /dev/null +++ b/user_guide_src/source/database/utilities/010.php @@ -0,0 +1,12 @@ +query('SELECT * FROM mytable'); + +$delimiter = ','; +$newline = "\r\n"; +$enclosure = '"'; + +echo $dbutil->getCSVFromResult($query, $delimiter, $newline, $enclosure); From e4d390313f85d153980ccd7cbf6580a85da2b3a7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 30 Nov 2023 12:54:57 +0900 Subject: [PATCH 2/4] docs: remove unimplemented repairTable() --- user_guide_src/source/database/utilities.rst | 11 ----------- user_guide_src/source/database/utilities/007.php | 7 ------- 2 files changed, 18 deletions(-) delete mode 100644 user_guide_src/source/database/utilities/007.php diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index eeb88cd1853d..c8c11e51d864 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -62,17 +62,6 @@ first parameter. Returns ``true``/``false`` based on success or failure: .. note:: Not all database platforms support table optimization. It is mostly for use with MySQL. -Repair a Table -============== - -Permits you to repair a table using the table name specified in the -first parameter. Returns ``true``/``false`` based on success or failure: - -.. literalinclude:: utilities/007.php - :lines: 2- - -.. note:: Not all database platforms support table repairs. - Optimize a Database =================== diff --git a/user_guide_src/source/database/utilities/007.php b/user_guide_src/source/database/utilities/007.php deleted file mode 100644 index 603b69cc9342..000000000000 --- a/user_guide_src/source/database/utilities/007.php +++ /dev/null @@ -1,7 +0,0 @@ -repairTable('table_name')) { - echo 'Success!'; -} From 7e55e4503fca0aef05416cbdf34e0fdeb2a06456 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 30 Nov 2023 12:58:12 +0900 Subject: [PATCH 3/4] docs: fix CI3's method name --- user_guide_src/source/database/utilities/006.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/database/utilities/006.php b/user_guide_src/source/database/utilities/006.php index 7fe39efdfdd8..6de4d1fdc6a7 100644 --- a/user_guide_src/source/database/utilities/006.php +++ b/user_guide_src/source/database/utilities/006.php @@ -2,6 +2,6 @@ $dbutil = \CodeIgniter\Database\Config::utils(); -if ($dbutil->optimize_table('table_name')) { +if ($dbutil->optimizeTable('table_name')) { echo 'Success!'; } From 4542dd58fbd79a97d36ef510088733e16c7b3a29 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 30 Nov 2023 16:07:28 +0900 Subject: [PATCH 4/4] docs: fix factory method name --- user_guide_src/source/database/utilities/004.php | 2 +- user_guide_src/source/database/utilities/005.php | 2 +- user_guide_src/source/database/utilities/006.php | 2 +- user_guide_src/source/database/utilities/008.php | 2 +- user_guide_src/source/database/utilities/009.php | 2 +- user_guide_src/source/database/utilities/010.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/database/utilities/004.php b/user_guide_src/source/database/utilities/004.php index 4a6b4f673859..3908bb7ad76c 100644 --- a/user_guide_src/source/database/utilities/004.php +++ b/user_guide_src/source/database/utilities/004.php @@ -1,6 +1,6 @@ listDatabases(); diff --git a/user_guide_src/source/database/utilities/005.php b/user_guide_src/source/database/utilities/005.php index 77b0310708e5..92ddaa3487ce 100644 --- a/user_guide_src/source/database/utilities/005.php +++ b/user_guide_src/source/database/utilities/005.php @@ -1,6 +1,6 @@ databaseExists('database_name')) { // some code... diff --git a/user_guide_src/source/database/utilities/006.php b/user_guide_src/source/database/utilities/006.php index 6de4d1fdc6a7..e85a07933798 100644 --- a/user_guide_src/source/database/utilities/006.php +++ b/user_guide_src/source/database/utilities/006.php @@ -1,6 +1,6 @@ optimizeTable('table_name')) { echo 'Success!'; diff --git a/user_guide_src/source/database/utilities/008.php b/user_guide_src/source/database/utilities/008.php index b5f19a33fd9e..726b15a822dd 100644 --- a/user_guide_src/source/database/utilities/008.php +++ b/user_guide_src/source/database/utilities/008.php @@ -1,6 +1,6 @@ optimizeDatabase(); diff --git a/user_guide_src/source/database/utilities/009.php b/user_guide_src/source/database/utilities/009.php index 054d88afa95e..f8bf84f6a499 100644 --- a/user_guide_src/source/database/utilities/009.php +++ b/user_guide_src/source/database/utilities/009.php @@ -1,7 +1,7 @@ query('SELECT * FROM mytable'); diff --git a/user_guide_src/source/database/utilities/010.php b/user_guide_src/source/database/utilities/010.php index c2b50a17360f..7e11cc18019b 100644 --- a/user_guide_src/source/database/utilities/010.php +++ b/user_guide_src/source/database/utilities/010.php @@ -1,7 +1,7 @@ query('SELECT * FROM mytable');