| |
| |
| <!DOCTYPE html> |
| <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> |
| <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| <title>Database Utility Class — CodeIgniter 3.1.10 documentation</title> |
| |
| |
| |
| |
| <link rel="shortcut icon" href="../_static/ci-icon.ico"/> |
| |
| |
| |
| <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" /> |
| |
| |
| |
| <link rel="index" title="Index" |
| href="../genindex.html"/> |
| <link rel="search" title="Search" href="../search.html"/> |
| <link rel="top" title="CodeIgniter 3.1.10 documentation" href="../index.html"/> |
| <link rel="up" title="Database Reference" href="index.html"/> |
| <link rel="next" title="DB Driver Reference" href="db_driver_reference.html"/> |
| <link rel="prev" title="Database Forge Class" href="forge.html"/> |
| |
| |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> |
| |
| </head> |
| |
| <body class="wy-body-for-nav" role="document"> |
| |
| <div id="nav"> |
| <div id="nav_inner"> |
| |
| |
| |
| <div id="pulldown-menu" class="ciNav"> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="current"> |
| <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li> |
| <li class="toctree-l2 current"><a class="current reference internal" href="#">Database Utilities Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| </ul> |
| </li> |
| </ul> |
| |
| </div> |
| |
| |
| </div> |
| </div> |
| <div id="nav2"> |
| <a href="#" id="openToc"> |
| <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" /> |
| </a> |
| </div> |
| |
| <div class="wy-grid-for-nav"> |
| |
| |
| <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| <div class="wy-side-nav-search"> |
| |
| <a href="../index.html" class="fa fa-home"> CodeIgniter</a> |
| |
| |
| <div role="search"> |
| <form id="rtd-search-form" class="wy-form" action="../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search docs" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| </div> |
| |
| <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
| |
| |
| |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="current"> |
| <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li> |
| <li class="toctree-l2 current"><a class="current reference internal" href="#">Database Utilities Class</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| </ul> |
| </li> |
| </ul> |
| |
| |
| |
| </div> |
| |
| </nav> |
| |
| <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| |
| |
| <nav class="wy-nav-top" role="navigation" aria-label="top navigation"> |
| <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| <a href="../index.html">CodeIgniter</a> |
| </nav> |
| |
| |
| |
| <div class="wy-nav-content"> |
| <div class="rst-content"> |
| <div role="navigation" aria-label="breadcrumbs navigation"> |
| <ul class="wy-breadcrumbs"> |
| <li><a href="../index.html">Docs</a> »</li> |
| |
| <li><a href="index.html">Database Reference</a> »</li> |
| |
| <li>Database Utility Class</li> |
| <li class="wy-breadcrumbs-aside"> |
| |
| </li> |
| <div style="float:right;margin-left:5px;" id="closeMe"> |
| <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" /> |
| </div> |
| </ul> |
| <hr/> |
| </div> |
| <div role="main" class="document"> |
| |
| <div class="section" id="database-utility-class"> |
| <h1>Database Utility Class<a class="headerlink" href="#database-utility-class" title="Permalink to this headline">¶</a></h1> |
| <p>The Database Utility Class contains methods that help you manage your |
| database.</p> |
| <div class="contents local topic" id="contents"> |
| <ul class="simple"> |
| <li><a class="reference internal" href="#initializing-the-utility-class" id="id1">Initializing the Utility Class</a></li> |
| <li><a class="reference internal" href="#using-the-database-utilities" id="id2">Using the Database Utilities</a><ul> |
| <li><a class="reference internal" href="#retrieve-list-of-database-names" id="id3">Retrieve list of database names</a></li> |
| <li><a class="reference internal" href="#determine-if-a-database-exists" id="id4">Determine If a Database Exists</a></li> |
| <li><a class="reference internal" href="#optimize-a-table" id="id5">Optimize a Table</a></li> |
| <li><a class="reference internal" href="#repair-a-table" id="id6">Repair a Table</a></li> |
| <li><a class="reference internal" href="#optimize-a-database" id="id7">Optimize a Database</a></li> |
| <li><a class="reference internal" href="#export-a-query-result-as-a-csv-file" id="id8">Export a Query Result as a CSV File</a></li> |
| <li><a class="reference internal" href="#export-a-query-result-as-an-xml-document" id="id9">Export a Query Result as an XML Document</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#backup-your-database" id="id10">Backup Your Database</a><ul> |
| <li><a class="reference internal" href="#database-backup-notes" id="id11">Database Backup Notes</a></li> |
| <li><a class="reference internal" href="#usage-example" id="id12">Usage Example</a></li> |
| <li><a class="reference internal" href="#setting-backup-preferences" id="id13">Setting Backup Preferences</a></li> |
| <li><a class="reference internal" href="#description-of-backup-preferences" id="id14">Description of Backup Preferences</a></li> |
| </ul> |
| </li> |
| <li><a class="reference internal" href="#class-reference" id="id15">Class Reference</a></li> |
| </ul> |
| </div> |
| <div class="section" id="initializing-the-utility-class"> |
| <h2><a class="toc-backref" href="#id1">Initializing the Utility Class</a><a class="headerlink" href="#initializing-the-utility-class" title="Permalink to this headline">¶</a></h2> |
| <div class="admonition important"> |
| <p class="first admonition-title">Important</p> |
| <p class="last">In order to initialize the Utility class, your database |
| driver must already be running, since the utilities class relies on it.</p> |
| </div> |
| <p>Load the Utility Class as follows:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">dbutil</span><span class="p">();</span> |
| </pre></div> |
| </div> |
| <p>You can also pass another database object to the DB Utility loader, in case |
| the database you want to manage isn’t the default one:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">myutil</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">dbutil</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">other_db</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <p>In the above example, we’re passing a custom database object as the first |
| parameter and then tell it to return the dbutil object, instead of |
| assigning it directly to <code class="docutils literal"><span class="pre">$this->dbutil</span></code>.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Both of the parameters can be used individually, just pass an empty |
| value as the first one if you wish to skip it.</p> |
| </div> |
| <p>Once initialized you will access the methods using the <code class="docutils literal"><span class="pre">$this->dbutil</span></code> |
| object:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">some_method</span><span class="p">();</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="using-the-database-utilities"> |
| <h2><a class="toc-backref" href="#id2">Using the Database Utilities</a><a class="headerlink" href="#using-the-database-utilities" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="retrieve-list-of-database-names"> |
| <h3><a class="toc-backref" href="#id3">Retrieve list of database names</a><a class="headerlink" href="#retrieve-list-of-database-names" title="Permalink to this headline">¶</a></h3> |
| <p>Returns an array of database names:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$dbs</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">list_databases</span><span class="p">();</span> |
| |
| <span class="k">foreach</span> <span class="p">(</span><span class="nv">$dbs</span> <span class="k">as</span> <span class="nv">$db</span><span class="p">)</span> |
| <span class="p">{</span> |
| <span class="k">echo</span> <span class="nv">$db</span><span class="p">;</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="determine-if-a-database-exists"> |
| <h3><a class="toc-backref" href="#id4">Determine If a Database Exists</a><a class="headerlink" href="#determine-if-a-database-exists" title="Permalink to this headline">¶</a></h3> |
| <p>Sometimes it’s helpful to know whether a particular database exists. |
| Returns a boolean TRUE/FALSE. Usage example:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">database_exists</span><span class="p">(</span><span class="s1">'database_name'</span><span class="p">))</span> |
| <span class="p">{</span> |
| <span class="c1">// some code...</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Replace <em>database_name</em> with the name of the database you are |
| looking for. This method is case sensitive.</p> |
| </div> |
| </div> |
| <div class="section" id="optimize-a-table"> |
| <h3><a class="toc-backref" href="#id5">Optimize a Table</a><a class="headerlink" href="#optimize-a-table" title="Permalink to this headline">¶</a></h3> |
| <p>Permits you to optimize a table using the table name specified in the |
| first parameter. Returns TRUE/FALSE based on success or failure:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">optimize_table</span><span class="p">(</span><span class="s1">'table_name'</span><span class="p">))</span> |
| <span class="p">{</span> |
| <span class="k">echo</span> <span class="s1">'Success!'</span><span class="p">;</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Not all database platforms support table optimization. It is |
| mostly for use with MySQL.</p> |
| </div> |
| </div> |
| <div class="section" id="repair-a-table"> |
| <h3><a class="toc-backref" href="#id6">Repair a Table</a><a class="headerlink" href="#repair-a-table" title="Permalink to this headline">¶</a></h3> |
| <p>Permits you to repair a table using the table name specified in the |
| first parameter. Returns TRUE/FALSE based on success or failure:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">repair_table</span><span class="p">(</span><span class="s1">'table_name'</span><span class="p">))</span> |
| <span class="p">{</span> |
| <span class="k">echo</span> <span class="s1">'Success!'</span><span class="p">;</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Not all database platforms support table repairs.</p> |
| </div> |
| </div> |
| <div class="section" id="optimize-a-database"> |
| <h3><a class="toc-backref" href="#id7">Optimize a Database</a><a class="headerlink" href="#optimize-a-database" title="Permalink to this headline">¶</a></h3> |
| <p>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.</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$result</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">optimize_database</span><span class="p">();</span> |
| |
| <span class="k">if</span> <span class="p">(</span><span class="nv">$result</span> <span class="o">!==</span> <span class="k">FALSE</span><span class="p">)</span> |
| <span class="p">{</span> |
| <span class="nb">print_r</span><span class="p">(</span><span class="nv">$result</span><span class="p">);</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Not all database platforms support database optimization. It |
| it is mostly for use with MySQL.</p> |
| </div> |
| </div> |
| <div class="section" id="export-a-query-result-as-a-csv-file"> |
| <h3><a class="toc-backref" href="#id8">Export a Query Result as a CSV File</a><a class="headerlink" href="#export-a-query-result-as-a-csv-file" title="Permalink to this headline">¶</a></h3> |
| <p>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:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">dbutil</span><span class="p">();</span> |
| |
| <span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">query</span><span class="p">(</span><span class="s2">"SELECT * FROM mytable"</span><span class="p">);</span> |
| |
| <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">csv_from_result</span><span class="p">(</span><span class="nv">$query</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <p>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:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$delimiter</span> <span class="o">=</span> <span class="s2">","</span><span class="p">;</span> |
| <span class="nv">$newline</span> <span class="o">=</span> <span class="s2">"</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">;</span> |
| <span class="nv">$enclosure</span> <span class="o">=</span> <span class="s1">'"'</span><span class="p">;</span> |
| |
| <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">csv_from_result</span><span class="p">(</span><span class="nv">$query</span><span class="p">,</span> <span class="nv">$delimiter</span><span class="p">,</span> <span class="nv">$newline</span><span class="p">,</span> <span class="nv">$enclosure</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <div class="admonition important"> |
| <p class="first admonition-title">Important</p> |
| <p class="last">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 <a class="reference internal" href="../helpers/file_helper.html"><span class="doc">File Helper</span></a>.</p> |
| </div> |
| </div> |
| <div class="section" id="export-a-query-result-as-an-xml-document"> |
| <h3><a class="toc-backref" href="#id9">Export a Query Result as an XML Document</a><a class="headerlink" href="#export-a-query-result-as-an-xml-document" title="Permalink to this headline">¶</a></h3> |
| <p>Permits you to generate an XML file from a query result. The first |
| parameter expects a query result object, the second may contain an |
| optional array of config parameters. Example:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">dbutil</span><span class="p">();</span> |
| |
| <span class="nv">$query</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">query</span><span class="p">(</span><span class="s2">"SELECT * FROM mytable"</span><span class="p">);</span> |
| |
| <span class="nv">$config</span> <span class="o">=</span> <span class="k">array</span> <span class="p">(</span> |
| <span class="s1">'root'</span> <span class="o">=></span> <span class="s1">'root'</span><span class="p">,</span> |
| <span class="s1">'element'</span> <span class="o">=></span> <span class="s1">'element'</span><span class="p">,</span> |
| <span class="s1">'newline'</span> <span class="o">=></span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">,</span> |
| <span class="s1">'tab'</span> <span class="o">=></span> <span class="s2">"</span><span class="se">\t</span><span class="s2">"</span> |
| <span class="p">);</span> |
| |
| <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">xml_from_result</span><span class="p">(</span><span class="nv">$query</span><span class="p">,</span> <span class="nv">$config</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <div class="admonition important"> |
| <p class="first admonition-title">Important</p> |
| <p class="last">This method will NOT write the XML file for you. It |
| simply creates the XML layout. If you need to write the file |
| use the <a class="reference internal" href="../helpers/file_helper.html"><span class="doc">File Helper</span></a>.</p> |
| </div> |
| </div> |
| </div> |
| <div class="section" id="backup-your-database"> |
| <h2><a class="toc-backref" href="#id10">Backup Your Database</a><a class="headerlink" href="#backup-your-database" title="Permalink to this headline">¶</a></h2> |
| <div class="section" id="database-backup-notes"> |
| <h3><a class="toc-backref" href="#id11">Database Backup Notes</a><a class="headerlink" href="#database-backup-notes" title="Permalink to this headline">¶</a></h3> |
| <p>Permits you to backup your full database or individual tables. The |
| backup data can be compressed in either Zip or Gzip format.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">This feature is only available for MySQL and Interbase/Firebird databases.</p> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p>For Interbase/Firebird databases, the backup file name is the only parameter.</p> |
| <p class="last">$this->dbutil->backup(‘db_backup_filename’);</p> |
| </div> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">Due to the limited execution time and memory available to PHP, |
| backing up very large databases may not be possible. If your database is |
| very large you might need to backup directly from your SQL server via |
| the command line, or have your server admin do it for you if you do not |
| have root privileges.</p> |
| </div> |
| </div> |
| <div class="section" id="usage-example"> |
| <h3><a class="toc-backref" href="#id12">Usage Example</a><a class="headerlink" href="#usage-example" title="Permalink to this headline">¶</a></h3> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Load the DB utility class</span> |
| <span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">dbutil</span><span class="p">();</span> |
| |
| <span class="c1">// Backup your entire database and assign it to a variable</span> |
| <span class="nv">$backup</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">backup</span><span class="p">();</span> |
| |
| <span class="c1">// Load the file helper and write the file to your server</span> |
| <span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">helper</span><span class="p">(</span><span class="s1">'file'</span><span class="p">);</span> |
| <span class="nx">write_file</span><span class="p">(</span><span class="s1">'/path/to/mybackup.gz'</span><span class="p">,</span> <span class="nv">$backup</span><span class="p">);</span> |
| |
| <span class="c1">// Load the download helper and send the file to your desktop</span> |
| <span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">helper</span><span class="p">(</span><span class="s1">'download'</span><span class="p">);</span> |
| <span class="nx">force_download</span><span class="p">(</span><span class="s1">'mybackup.gz'</span><span class="p">,</span> <span class="nv">$backup</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="setting-backup-preferences"> |
| <h3><a class="toc-backref" href="#id13">Setting Backup Preferences</a><a class="headerlink" href="#setting-backup-preferences" title="Permalink to this headline">¶</a></h3> |
| <p>Backup preferences are set by submitting an array of values to the first |
| parameter of the <code class="docutils literal"><span class="pre">backup()</span></code> method. Example:</p> |
| <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$prefs</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| <span class="s1">'tables'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span><span class="s1">'table1'</span><span class="p">,</span> <span class="s1">'table2'</span><span class="p">),</span> <span class="c1">// Array of tables to backup.</span> |
| <span class="s1">'ignore'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(),</span> <span class="c1">// List of tables to omit from the backup</span> |
| <span class="s1">'format'</span> <span class="o">=></span> <span class="s1">'txt'</span><span class="p">,</span> <span class="c1">// gzip, zip, txt</span> |
| <span class="s1">'filename'</span> <span class="o">=></span> <span class="s1">'mybackup.sql'</span><span class="p">,</span> <span class="c1">// File name - NEEDED ONLY WITH ZIP FILES</span> |
| <span class="s1">'add_drop'</span> <span class="o">=></span> <span class="k">TRUE</span><span class="p">,</span> <span class="c1">// Whether to add DROP TABLE statements to backup file</span> |
| <span class="s1">'add_insert'</span> <span class="o">=></span> <span class="k">TRUE</span><span class="p">,</span> <span class="c1">// Whether to add INSERT data to backup file</span> |
| <span class="s1">'newline'</span> <span class="o">=></span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span> <span class="c1">// Newline character used in backup file</span> |
| <span class="p">);</span> |
| |
| <span class="nv">$this</span><span class="o">-></span><span class="na">dbutil</span><span class="o">-></span><span class="na">backup</span><span class="p">(</span><span class="nv">$prefs</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="description-of-backup-preferences"> |
| <h3><a class="toc-backref" href="#id14">Description of Backup Preferences</a><a class="headerlink" href="#description-of-backup-preferences" title="Permalink to this headline">¶</a></h3> |
| <table border="1" class="docutils"> |
| <colgroup> |
| <col width="16%" /> |
| <col width="16%" /> |
| <col width="16%" /> |
| <col width="51%" /> |
| </colgroup> |
| <thead valign="bottom"> |
| <tr class="row-odd"><th class="head">Preference</th> |
| <th class="head">Default Value</th> |
| <th class="head">Options</th> |
| <th class="head">Description</th> |
| </tr> |
| </thead> |
| <tbody valign="top"> |
| <tr class="row-even"><td><strong>tables</strong></td> |
| <td>empty array</td> |
| <td>None</td> |
| <td>An array of tables you want backed up. If left blank all tables will be |
| exported.</td> |
| </tr> |
| <tr class="row-odd"><td><strong>ignore</strong></td> |
| <td>empty array</td> |
| <td>None</td> |
| <td>An array of tables you want the backup routine to ignore.</td> |
| </tr> |
| <tr class="row-even"><td><strong>format</strong></td> |
| <td>gzip</td> |
| <td>gzip, zip, txt</td> |
| <td>The file format of the export file.</td> |
| </tr> |
| <tr class="row-odd"><td><strong>filename</strong></td> |
| <td>the current date/time</td> |
| <td>None</td> |
| <td>The name of the backed-up file. The name is needed only if you are using |
| zip compression.</td> |
| </tr> |
| <tr class="row-even"><td><strong>add_drop</strong></td> |
| <td>TRUE</td> |
| <td>TRUE/FALSE</td> |
| <td>Whether to include DROP TABLE statements in your SQL export file.</td> |
| </tr> |
| <tr class="row-odd"><td><strong>add_insert</strong></td> |
| <td>TRUE</td> |
| <td>TRUE/FALSE</td> |
| <td>Whether to include INSERT statements in your SQL export file.</td> |
| </tr> |
| <tr class="row-even"><td><strong>newline</strong></td> |
| <td>“\n”</td> |
| <td>“\n”, “\r”, “\r\n”</td> |
| <td>Type of newline to use in your SQL export file.</td> |
| </tr> |
| <tr class="row-odd"><td><strong>foreign_key_checks</strong></td> |
| <td>TRUE</td> |
| <td>TRUE/FALSE</td> |
| <td>Whether output should keep foreign key checks enabled.</td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div class="section" id="class-reference"> |
| <h2><a class="toc-backref" href="#id15">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2> |
| <dl class="class"> |
| <dt id="CI_DB_utility"> |
| <em class="property">class </em><code class="descname">CI_DB_utility</code><a class="headerlink" href="#CI_DB_utility" title="Permalink to this definition">¶</a></dt> |
| <dd><dl class="method"> |
| <dt id="CI_DB_utility::backup"> |
| <code class="descname">backup</code><span class="sig-paren">(</span><span class="optional">[</span><em>$params = array()</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::backup" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$params</strong> (<em>array</em>) – An associative array of options</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">raw/(g)zipped SQL query string</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Perform a database backup, per user preferences.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::database_exists"> |
| <code class="descname">database_exists</code><span class="sig-paren">(</span><em>$database_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::database_exists" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$database_name</strong> (<em>string</em>) – Database name</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE if the database exists, FALSE otherwise</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Check for the existence of a database.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::list_databases"> |
| <code class="descname">list_databases</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::list_databases" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array of database names found</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Retrieve a list of all the database names.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::optimize_database"> |
| <code class="descname">optimize_database</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::optimize_database" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array of optimization messages or FALSE on failure</td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Optimizes the database.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::optimize_table"> |
| <code class="descname">optimize_table</code><span class="sig-paren">(</span><em>$table_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::optimize_table" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$table_name</strong> (<em>string</em>) – Name of the table to optimize</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array of optimization messages or FALSE on failure</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">array</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Optimizes a database table.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::repair_table"> |
| <code class="descname">repair_table</code><span class="sig-paren">(</span><em>$table_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::repair_table" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$table_name</strong> (<em>string</em>) – Name of the table to repair</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array of repair messages or FALSE on failure</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">array</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Repairs a database table.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::csv_from_result"> |
| <code class="descname">csv_from_result</code><span class="sig-paren">(</span><em>$query</em><span class="optional">[</span>, <em>$delim = '</em>, <em>'</em><span class="optional">[</span>, <em>$newline = "n"</em><span class="optional">[</span>, <em>$enclosure = '"'</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::csv_from_result" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$query</strong> (<em>object</em>) – A database result object</li> |
| <li><strong>$delim</strong> (<em>string</em>) – The CSV field delimiter to use</li> |
| <li><strong>$newline</strong> (<em>string</em>) – The newline character to use</li> |
| <li><strong>$enclosure</strong> (<em>string</em>) – The enclosure delimiter to use</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The generated CSV file as a string</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Translates a database result object into a CSV document.</p> |
| </dd></dl> |
| |
| <dl class="method"> |
| <dt id="CI_DB_utility::xml_from_result"> |
| <code class="descname">xml_from_result</code><span class="sig-paren">(</span><em>$query</em><span class="optional">[</span>, <em>$params = array()</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_utility::xml_from_result" title="Permalink to this definition">¶</a></dt> |
| <dd><table class="docutils field-list" frame="void" rules="none"> |
| <col class="field-name" /> |
| <col class="field-body" /> |
| <tbody valign="top"> |
| <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| <li><strong>$query</strong> (<em>object</em>) – A database result object</li> |
| <li><strong>$params</strong> (<em>array</em>) – An associative array of preferences</li> |
| </ul> |
| </td> |
| </tr> |
| <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The generated XML document as a string</p> |
| </td> |
| </tr> |
| <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <p>Translates a database result object into an XML document.</p> |
| </dd></dl> |
| |
| </dd></dl> |
| |
| </div> |
| </div> |
| |
| |
| </div> |
| <footer> |
| |
| <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| |
| <a href="db_driver_reference.html" class="btn btn-neutral float-right" title="DB Driver Reference">Next <span class="fa fa-arrow-circle-right"></span></a> |
| |
| |
| <a href="forge.html" class="btn btn-neutral" title="Database Forge Class"><span class="fa fa-arrow-circle-left"></span> Previous</a> |
| |
| </div> |
| |
| |
| <hr/> |
| |
| <div role="contentinfo"> |
| <p> |
| © Copyright 2014 - 2019, British Columbia Institute of Technology. |
| Last updated on Jan 16, 2019. |
| </p> |
| </div> |
| |
| Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. |
| |
| </footer> |
| </div> |
| </div> |
| |
| </section> |
| |
| </div> |
| |
| |
| |
| |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT:'../', |
| VERSION:'3.1.10', |
| COLLAPSE_INDEX:false, |
| FILE_SUFFIX:'.html', |
| HAS_SOURCE: false |
| }; |
| </script> |
| <script type="text/javascript" src="../_static/jquery.js"></script> |
| <script type="text/javascript" src="../_static/underscore.js"></script> |
| <script type="text/javascript" src="../_static/doctools.js"></script> |
| |
| |
| |
| |
| |
| <script type="text/javascript" src="../_static/js/theme.js"></script> |
| |
| |
| |
| |
| <script type="text/javascript"> |
| jQuery(function () { |
| SphinxRtdTheme.StickyNav.enable(); |
| }); |
| </script> |
| |
| |
| </body> |
| </html> |