Andrey Andreev | c576995 | 2019-01-16 17:49:35 +0200 | [diff] [blame^] | 1 | |
| 2 | |
| 3 | <!DOCTYPE html> |
| 4 | <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]--> |
| 5 | <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]--> |
| 6 | <head> |
| 7 | <meta charset="utf-8"> |
| 8 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 9 | |
| 10 | <title>Query Builder Class — CodeIgniter 3.1.10 documentation</title> |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | <link rel="shortcut icon" href="../_static/ci-icon.ico"/> |
| 16 | |
| 17 | |
| 18 | |
| 19 | <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'> |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" /> |
| 30 | |
| 31 | |
| 32 | |
| 33 | <link rel="index" title="Index" |
| 34 | href="../genindex.html"/> |
| 35 | <link rel="search" title="Search" href="../search.html"/> |
| 36 | <link rel="top" title="CodeIgniter 3.1.10 documentation" href="../index.html"/> |
| 37 | <link rel="up" title="Database Reference" href="index.html"/> |
| 38 | <link rel="next" title="Transactions" href="transactions.html"/> |
| 39 | <link rel="prev" title="Query Helper Methods" href="helpers.html"/> |
| 40 | |
| 41 | |
| 42 | <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> |
| 43 | |
| 44 | </head> |
| 45 | |
| 46 | <body class="wy-body-for-nav" role="document"> |
| 47 | |
| 48 | <div id="nav"> |
| 49 | <div id="nav_inner"> |
| 50 | |
| 51 | |
| 52 | |
| 53 | <div id="pulldown-menu" class="ciNav"> |
| 54 | <ul> |
| 55 | <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| 56 | </ul> |
| 57 | <ul> |
| 58 | <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| 59 | <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| 60 | <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| 61 | <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| 62 | <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| 63 | </ul> |
| 64 | </li> |
| 65 | </ul> |
| 66 | <ul> |
| 67 | <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| 68 | <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| 69 | <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| 70 | <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| 71 | <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| 72 | <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| 73 | <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| 74 | </ul> |
| 75 | </li> |
| 76 | </ul> |
| 77 | <ul> |
| 78 | <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| 79 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| 80 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| 81 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| 82 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| 83 | </ul> |
| 84 | </li> |
| 85 | </ul> |
| 86 | <ul> |
| 87 | <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| 88 | <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| 89 | <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| 90 | </ul> |
| 91 | </li> |
| 92 | </ul> |
| 93 | <ul> |
| 94 | <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| 95 | <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| 96 | <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| 97 | <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| 98 | <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| 99 | <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| 100 | <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| 101 | <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| 102 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| 103 | <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| 104 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| 105 | <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| 106 | <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| 107 | <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| 108 | <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| 109 | <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| 110 | <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| 111 | <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| 112 | <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| 113 | <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| 114 | <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| 115 | <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| 116 | <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| 117 | <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| 118 | <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| 119 | <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| 120 | <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| 121 | </ul> |
| 122 | </li> |
| 123 | </ul> |
| 124 | <ul> |
| 125 | <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul> |
| 126 | <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li> |
| 127 | <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li> |
| 128 | <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li> |
| 129 | <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li> |
| 130 | <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li> |
| 131 | <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li> |
| 132 | <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li> |
| 133 | <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li> |
| 134 | <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li> |
| 135 | <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li> |
| 136 | <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li> |
| 137 | <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li> |
| 138 | <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li> |
| 139 | <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li> |
| 140 | <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li> |
| 141 | <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li> |
| 142 | <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li> |
| 143 | <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li> |
| 144 | <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li> |
| 145 | <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li> |
| 146 | <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li> |
| 147 | <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li> |
| 148 | <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li> |
| 149 | <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li> |
| 150 | <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li> |
| 151 | <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li> |
| 152 | <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li> |
| 153 | <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li> |
| 154 | <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| 155 | <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li> |
| 156 | </ul> |
| 157 | </li> |
| 158 | </ul> |
| 159 | <ul class="current"> |
| 160 | <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current"> |
| 161 | <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li> |
| 162 | <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li> |
| 163 | <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li> |
| 164 | <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li> |
| 165 | <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li> |
| 166 | <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li> |
| 167 | <li class="toctree-l2 current"><a class="current reference internal" href="#">Query Builder Class</a></li> |
| 168 | <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li> |
| 169 | <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li> |
| 170 | <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li> |
| 171 | <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li> |
| 172 | <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li> |
| 173 | <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li> |
| 174 | <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li> |
| 175 | </ul> |
| 176 | </li> |
| 177 | </ul> |
| 178 | <ul> |
| 179 | <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| 180 | <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| 181 | <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| 182 | <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| 183 | <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| 184 | <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| 185 | <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| 186 | <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| 187 | <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| 188 | <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| 189 | <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| 190 | <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| 191 | <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| 192 | <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| 193 | <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| 194 | <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| 195 | <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| 196 | <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| 197 | <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| 198 | <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| 199 | <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| 200 | <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| 201 | </ul> |
| 202 | </li> |
| 203 | </ul> |
| 204 | |
| 205 | </div> |
| 206 | |
| 207 | |
| 208 | </div> |
| 209 | </div> |
| 210 | <div id="nav2"> |
| 211 | <a href="#" id="openToc"> |
| 212 | <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" /> |
| 213 | </a> |
| 214 | </div> |
| 215 | |
| 216 | <div class="wy-grid-for-nav"> |
| 217 | |
| 218 | |
| 219 | <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| 220 | <div class="wy-side-nav-search"> |
| 221 | |
| 222 | <a href="../index.html" class="fa fa-home"> CodeIgniter</a> |
| 223 | |
| 224 | |
| 225 | <div role="search"> |
| 226 | <form id="rtd-search-form" class="wy-form" action="../search.html" method="get"> |
| 227 | <input type="text" name="q" placeholder="Search docs" /> |
| 228 | <input type="hidden" name="check_keywords" value="yes" /> |
| 229 | <input type="hidden" name="area" value="default" /> |
| 230 | </form> |
| 231 | </div> |
| 232 | </div> |
| 233 | |
| 234 | <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
| 235 | |
| 236 | |
| 237 | |
| 238 | <ul> |
| 239 | <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li> |
| 240 | </ul> |
| 241 | <ul> |
| 242 | <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul> |
| 243 | <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li> |
| 244 | <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li> |
| 245 | <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li> |
| 246 | <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li> |
| 247 | </ul> |
| 248 | </li> |
| 249 | </ul> |
| 250 | <ul> |
| 251 | <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul> |
| 252 | <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li> |
| 253 | <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li> |
| 254 | <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li> |
| 255 | <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li> |
| 256 | <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li> |
| 257 | <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li> |
| 258 | </ul> |
| 259 | </li> |
| 260 | </ul> |
| 261 | <ul> |
| 262 | <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul> |
| 263 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li> |
| 264 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li> |
| 265 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li> |
| 266 | <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li> |
| 267 | </ul> |
| 268 | </li> |
| 269 | </ul> |
| 270 | <ul> |
| 271 | <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul> |
| 272 | <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li> |
| 273 | <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li> |
| 274 | </ul> |
| 275 | </li> |
| 276 | </ul> |
| 277 | <ul> |
| 278 | <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul> |
| 279 | <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li> |
| 280 | <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li> |
| 281 | <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li> |
| 282 | <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li> |
| 283 | <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li> |
| 284 | <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li> |
| 285 | <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li> |
| 286 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li> |
| 287 | <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li> |
| 288 | <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li> |
| 289 | <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li> |
| 290 | <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li> |
| 291 | <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li> |
| 292 | <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li> |
| 293 | <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li> |
| 294 | <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li> |
| 295 | <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li> |
| 296 | <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li> |
| 297 | <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li> |
| 298 | <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li> |
| 299 | <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li> |
| 300 | <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li> |
| 301 | <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li> |
| 302 | <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li> |
| 303 | <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li> |
| 304 | <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li> |
| 305 | </ul> |
| 306 | </li> |
| 307 | </ul> |
| 308 | <ul> |
| 309 | <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul> |
| 310 | <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li> |
| 311 | <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li> |
| 312 | <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li> |
| 313 | <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li> |
| 314 | <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li> |
| 315 | <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li> |
| 316 | <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li> |
| 317 | <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li> |
| 318 | <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li> |
| 319 | <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li> |
| 320 | <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li> |
| 321 | <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li> |
| 322 | <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li> |
| 323 | <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li> |
| 324 | <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li> |
| 325 | <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li> |
| 326 | <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li> |
| 327 | <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li> |
| 328 | <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li> |
| 329 | <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li> |
| 330 | <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li> |
| 331 | <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li> |
| 332 | <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li> |
| 333 | <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li> |
| 334 | <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li> |
| 335 | <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li> |
| 336 | <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li> |
| 337 | <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li> |
| 338 | <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li> |
| 339 | <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li> |
| 340 | </ul> |
| 341 | </li> |
| 342 | </ul> |
| 343 | <ul class="current"> |
| 344 | <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current"> |
| 345 | <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li> |
| 346 | <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li> |
| 347 | <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li> |
| 348 | <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li> |
| 349 | <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li> |
| 350 | <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li> |
| 351 | <li class="toctree-l2 current"><a class="current reference internal" href="#">Query Builder Class</a></li> |
| 352 | <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li> |
| 353 | <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li> |
| 354 | <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li> |
| 355 | <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li> |
| 356 | <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li> |
| 357 | <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li> |
| 358 | <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li> |
| 359 | </ul> |
| 360 | </li> |
| 361 | </ul> |
| 362 | <ul> |
| 363 | <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul> |
| 364 | <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li> |
| 365 | <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li> |
| 366 | <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li> |
| 367 | <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li> |
| 368 | <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li> |
| 369 | <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li> |
| 370 | <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li> |
| 371 | <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li> |
| 372 | <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li> |
| 373 | <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li> |
| 374 | <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li> |
| 375 | <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li> |
| 376 | <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li> |
| 377 | <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li> |
| 378 | <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li> |
| 379 | <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li> |
| 380 | <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li> |
| 381 | <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li> |
| 382 | <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li> |
| 383 | <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li> |
| 384 | <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li> |
| 385 | </ul> |
| 386 | </li> |
| 387 | </ul> |
| 388 | |
| 389 | |
| 390 | |
| 391 | </div> |
| 392 | |
| 393 | </nav> |
| 394 | |
| 395 | <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| 396 | |
| 397 | |
| 398 | <nav class="wy-nav-top" role="navigation" aria-label="top navigation"> |
| 399 | <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| 400 | <a href="../index.html">CodeIgniter</a> |
| 401 | </nav> |
| 402 | |
| 403 | |
| 404 | |
| 405 | <div class="wy-nav-content"> |
| 406 | <div class="rst-content"> |
| 407 | <div role="navigation" aria-label="breadcrumbs navigation"> |
| 408 | <ul class="wy-breadcrumbs"> |
| 409 | <li><a href="../index.html">Docs</a> »</li> |
| 410 | |
| 411 | <li><a href="index.html">Database Reference</a> »</li> |
| 412 | |
| 413 | <li>Query Builder Class</li> |
| 414 | <li class="wy-breadcrumbs-aside"> |
| 415 | |
| 416 | </li> |
| 417 | <div style="float:right;margin-left:5px;" id="closeMe"> |
| 418 | <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" /> |
| 419 | </div> |
| 420 | </ul> |
| 421 | <hr/> |
| 422 | </div> |
| 423 | <div role="main" class="document"> |
| 424 | |
| 425 | <div class="section" id="query-builder-class"> |
| 426 | <h1>Query Builder Class<a class="headerlink" href="#query-builder-class" title="Permalink to this headline">¶</a></h1> |
| 427 | <p>CodeIgniter gives you access to a Query Builder class. This pattern |
| 428 | allows information to be retrieved, inserted, and updated in your |
| 429 | database with minimal scripting. In some cases only one or two lines |
| 430 | of code are necessary to perform a database action. |
| 431 | CodeIgniter does not require that each database table be its own class |
| 432 | file. It instead provides a more simplified interface.</p> |
| 433 | <p>Beyond simplicity, a major benefit to using the Query Builder features |
| 434 | is that it allows you to create database independent applications, since |
| 435 | the query syntax is generated by each database adapter. It also allows |
| 436 | for safer queries, since the values are escaped automatically by the |
| 437 | system.</p> |
| 438 | <div class="admonition note"> |
| 439 | <p class="first admonition-title">Note</p> |
| 440 | <p class="last">If you intend to write your own queries you can disable this |
| 441 | class in your database config file, allowing the core database library |
| 442 | and adapter to utilize fewer resources.</p> |
| 443 | </div> |
| 444 | <div class="contents local topic" id="contents"> |
| 445 | <ul class="simple"> |
| 446 | <li><a class="reference internal" href="#selecting-data" id="id1">Selecting Data</a></li> |
| 447 | <li><a class="reference internal" href="#looking-for-specific-data" id="id2">Looking for Specific Data</a></li> |
| 448 | <li><a class="reference internal" href="#looking-for-similar-data" id="id3">Looking for Similar Data</a></li> |
| 449 | <li><a class="reference internal" href="#ordering-results" id="id4">Ordering results</a></li> |
| 450 | <li><a class="reference internal" href="#limiting-or-counting-results" id="id5">Limiting or Counting Results</a></li> |
| 451 | <li><a class="reference internal" href="#query-grouping" id="id6">Query grouping</a></li> |
| 452 | <li><a class="reference internal" href="#inserting-data" id="id7">Inserting Data</a></li> |
| 453 | <li><a class="reference internal" href="#updating-data" id="id8">Updating Data</a></li> |
| 454 | <li><a class="reference internal" href="#deleting-data" id="id9">Deleting Data</a></li> |
| 455 | <li><a class="reference internal" href="#method-chaining" id="id10">Method Chaining</a></li> |
| 456 | <li><a class="reference internal" href="#query-builder-caching" id="id11">Query Builder Caching</a></li> |
| 457 | <li><a class="reference internal" href="#resetting-query-builder" id="id12">Resetting Query Builder</a></li> |
| 458 | <li><a class="reference internal" href="#class-reference" id="id13">Class Reference</a></li> |
| 459 | </ul> |
| 460 | </div> |
| 461 | <div class="section" id="selecting-data"> |
| 462 | <h2><a class="toc-backref" href="#id1">Selecting Data</a><a class="headerlink" href="#selecting-data" title="Permalink to this headline">¶</a></h2> |
| 463 | <p>The following functions allow you to build SQL <strong>SELECT</strong> statements.</p> |
| 464 | <p><strong>$this->db->get()</strong></p> |
| 465 | <p>Runs the selection query and returns the result. Can be used by itself |
| 466 | to retrieve all records from a table:</p> |
| 467 | <div class="highlight-ci"><div class="highlight"><pre><span></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">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> <span class="c1">// Produces: SELECT * FROM mytable</span> |
| 468 | </pre></div> |
| 469 | </div> |
| 470 | <p>The second and third parameters enable you to set a limit and offset |
| 471 | clause:</p> |
| 472 | <div class="highlight-ci"><div class="highlight"><pre><span></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">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">);</span> |
| 473 | |
| 474 | <span class="c1">// Executes: SELECT * FROM mytable LIMIT 20, 10</span> |
| 475 | <span class="c1">// (in MySQL. Other databases have slightly different syntax)</span> |
| 476 | </pre></div> |
| 477 | </div> |
| 478 | <p>You’ll notice that the above function is assigned to a variable named |
| 479 | $query, which can be used to show the results:</p> |
| 480 | <div class="highlight-ci"><div class="highlight"><pre><span></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">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 481 | |
| 482 | <span class="k">foreach</span> <span class="p">(</span><span class="nv">$query</span><span class="o">-></span><span class="na">result</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$row</span><span class="p">)</span> |
| 483 | <span class="p">{</span> |
| 484 | <span class="k">echo</span> <span class="nv">$row</span><span class="o">-></span><span class="na">title</span><span class="p">;</span> |
| 485 | <span class="p">}</span> |
| 486 | </pre></div> |
| 487 | </div> |
| 488 | <p>Please visit the <a class="reference internal" href="results.html"><span class="doc">result functions</span></a> page for a full |
| 489 | discussion regarding result generation.</p> |
| 490 | <p><strong>$this->db->get_compiled_select()</strong></p> |
| 491 | <p>Compiles the selection query just like <strong>$this->db->get()</strong> but does not <em>run</em> |
| 492 | the query. This method simply returns the SQL query as a string.</p> |
| 493 | <p>Example:</p> |
| 494 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$sql</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">get_compiled_select</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 495 | <span class="k">echo</span> <span class="nv">$sql</span><span class="p">;</span> |
| 496 | |
| 497 | <span class="c1">// Prints string: SELECT * FROM mytable</span> |
| 498 | </pre></div> |
| 499 | </div> |
| 500 | <p>The second parameter enables you to set whether or not the query builder query |
| 501 | will be reset (by default it will be reset, just like when using <cite>$this->db->get()</cite>):</p> |
| 502 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">limit</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">)</span><span class="o">-></span><span class="na">get_compiled_select</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 503 | |
| 504 | <span class="c1">// Prints string: SELECT * FROM mytable LIMIT 20, 10</span> |
| 505 | <span class="c1">// (in MySQL. Other databases have slightly different syntax)</span> |
| 506 | |
| 507 | <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'title, content, date'</span><span class="p">)</span><span class="o">-></span><span class="na">get_compiled_select</span><span class="p">();</span> |
| 508 | |
| 509 | <span class="c1">// Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10</span> |
| 510 | </pre></div> |
| 511 | </div> |
| 512 | <p>The key thing to notice in the above example is that the second query did not |
| 513 | utilize <strong>$this->db->from()</strong> and did not pass a table name into the first |
| 514 | parameter. The reason for this outcome is because the query has not been |
| 515 | executed using <strong>$this->db->get()</strong> which resets values or reset directly |
| 516 | using <strong>$this->db->reset_query()</strong>.</p> |
| 517 | <p><strong>$this->db->get_where()</strong></p> |
| 518 | <p>Identical to the above function except that it permits you to add a |
| 519 | “where” clause in the second parameter, instead of using the db->where() |
| 520 | function:</p> |
| 521 | <div class="highlight-ci"><div class="highlight"><pre><span></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">get_where</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">'id'</span> <span class="o">=></span> <span class="nv">$id</span><span class="p">),</span> <span class="nv">$limit</span><span class="p">,</span> <span class="nv">$offset</span><span class="p">);</span> |
| 522 | </pre></div> |
| 523 | </div> |
| 524 | <p>Please read the about the where function below for more information.</p> |
| 525 | <div class="admonition note"> |
| 526 | <p class="first admonition-title">Note</p> |
| 527 | <p class="last">get_where() was formerly known as getwhere(), which has been removed</p> |
| 528 | </div> |
| 529 | <p><strong>$this->db->select()</strong></p> |
| 530 | <p>Permits you to write the SELECT portion of your query:</p> |
| 531 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'title, content, date'</span><span class="p">);</span> |
| 532 | <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">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 533 | |
| 534 | <span class="c1">// Executes: SELECT title, content, date FROM mytable</span> |
| 535 | </pre></div> |
| 536 | </div> |
| 537 | <div class="admonition note"> |
| 538 | <p class="first admonition-title">Note</p> |
| 539 | <p class="last">If you are selecting all (*) from a table you do not need to |
| 540 | use this function. When omitted, CodeIgniter assumes that you wish |
| 541 | to select all fields and automatically adds ‘SELECT *’.</p> |
| 542 | </div> |
| 543 | <p><code class="docutils literal"><span class="pre">$this->db->select()</span></code> accepts an optional second parameter. If you set it |
| 544 | to FALSE, CodeIgniter will not try to protect your field or table names. |
| 545 | This is useful if you need a compound select statement where automatic |
| 546 | escaping of fields may break them.</p> |
| 547 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4) AS amount_paid'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 548 | <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">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 549 | </pre></div> |
| 550 | </div> |
| 551 | <p><strong>$this->db->select_max()</strong></p> |
| 552 | <p>Writes a <code class="docutils literal"><span class="pre">SELECT</span> <span class="pre">MAX(field)</span></code> portion for your query. You can optionally |
| 553 | include a second parameter to rename the resulting field.</p> |
| 554 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select_max</span><span class="p">(</span><span class="s1">'age'</span><span class="p">);</span> |
| 555 | <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">get</span><span class="p">(</span><span class="s1">'members'</span><span class="p">);</span> <span class="c1">// Produces: SELECT MAX(age) as age FROM members</span> |
| 556 | |
| 557 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select_max</span><span class="p">(</span><span class="s1">'age'</span><span class="p">,</span> <span class="s1">'member_age'</span><span class="p">);</span> |
| 558 | <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">get</span><span class="p">(</span><span class="s1">'members'</span><span class="p">);</span> <span class="c1">// Produces: SELECT MAX(age) as member_age FROM members</span> |
| 559 | </pre></div> |
| 560 | </div> |
| 561 | <p><strong>$this->db->select_min()</strong></p> |
| 562 | <p>Writes a “SELECT MIN(field)” portion for your query. As with |
| 563 | select_max(), You can optionally include a second parameter to rename |
| 564 | the resulting field.</p> |
| 565 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select_min</span><span class="p">(</span><span class="s1">'age'</span><span class="p">);</span> |
| 566 | <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">get</span><span class="p">(</span><span class="s1">'members'</span><span class="p">);</span> <span class="c1">// Produces: SELECT MIN(age) as age FROM members</span> |
| 567 | </pre></div> |
| 568 | </div> |
| 569 | <p><strong>$this->db->select_avg()</strong></p> |
| 570 | <p>Writes a “SELECT AVG(field)” portion for your query. As with |
| 571 | select_max(), You can optionally include a second parameter to rename |
| 572 | the resulting field.</p> |
| 573 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select_avg</span><span class="p">(</span><span class="s1">'age'</span><span class="p">);</span> |
| 574 | <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">get</span><span class="p">(</span><span class="s1">'members'</span><span class="p">);</span> <span class="c1">// Produces: SELECT AVG(age) as age FROM members</span> |
| 575 | </pre></div> |
| 576 | </div> |
| 577 | <p><strong>$this->db->select_sum()</strong></p> |
| 578 | <p>Writes a “SELECT SUM(field)” portion for your query. As with |
| 579 | select_max(), You can optionally include a second parameter to rename |
| 580 | the resulting field.</p> |
| 581 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select_sum</span><span class="p">(</span><span class="s1">'age'</span><span class="p">);</span> |
| 582 | <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">get</span><span class="p">(</span><span class="s1">'members'</span><span class="p">);</span> <span class="c1">// Produces: SELECT SUM(age) as age FROM members</span> |
| 583 | </pre></div> |
| 584 | </div> |
| 585 | <p><strong>$this->db->from()</strong></p> |
| 586 | <p>Permits you to write the FROM portion of your query:</p> |
| 587 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'title, content, date'</span><span class="p">);</span> |
| 588 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">from</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 589 | <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">get</span><span class="p">();</span> <span class="c1">// Produces: SELECT title, content, date FROM mytable</span> |
| 590 | </pre></div> |
| 591 | </div> |
| 592 | <div class="admonition note"> |
| 593 | <p class="first admonition-title">Note</p> |
| 594 | <p class="last">As shown earlier, the FROM portion of your query can be specified |
| 595 | in the $this->db->get() function, so use whichever method you prefer.</p> |
| 596 | </div> |
| 597 | <p><strong>$this->db->join()</strong></p> |
| 598 | <p>Permits you to write the JOIN portion of your query:</p> |
| 599 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'*'</span><span class="p">);</span> |
| 600 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">from</span><span class="p">(</span><span class="s1">'blogs'</span><span class="p">);</span> |
| 601 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">join</span><span class="p">(</span><span class="s1">'comments'</span><span class="p">,</span> <span class="s1">'comments.id = blogs.id'</span><span class="p">);</span> |
| 602 | <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">get</span><span class="p">();</span> |
| 603 | |
| 604 | <span class="c1">// Produces:</span> |
| 605 | <span class="c1">// SELECT * FROM blogs JOIN comments ON comments.id = blogs.id</span> |
| 606 | </pre></div> |
| 607 | </div> |
| 608 | <p>Multiple function calls can be made if you need several joins in one |
| 609 | query.</p> |
| 610 | <p>If you need a specific type of JOIN you can specify it via the third |
| 611 | parameter of the function. Options are: left, right, outer, inner, left |
| 612 | outer, and right outer.</p> |
| 613 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">join</span><span class="p">(</span><span class="s1">'comments'</span><span class="p">,</span> <span class="s1">'comments.id = blogs.id'</span><span class="p">,</span> <span class="s1">'left'</span><span class="p">);</span> |
| 614 | <span class="c1">// Produces: LEFT JOIN comments ON comments.id = blogs.id</span> |
| 615 | </pre></div> |
| 616 | </div> |
| 617 | </div> |
| 618 | <div class="section" id="looking-for-specific-data"> |
| 619 | <h2><a class="toc-backref" href="#id2">Looking for Specific Data</a><a class="headerlink" href="#looking-for-specific-data" title="Permalink to this headline">¶</a></h2> |
| 620 | <p><strong>$this->db->where()</strong></p> |
| 621 | <p>This function enables you to set <strong>WHERE</strong> clauses using one of four |
| 622 | methods:</p> |
| 623 | <div class="admonition note"> |
| 624 | <p class="first admonition-title">Note</p> |
| 625 | <p class="last">All values passed to this function are escaped automatically, |
| 626 | producing safer queries.</p> |
| 627 | </div> |
| 628 | <ol class="arabic"> |
| 629 | <li><p class="first"><strong>Simple key/value method:</strong></p> |
| 630 | <blockquote> |
| 631 | <div><div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'name'</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> <span class="c1">// Produces: WHERE name = 'Joe'</span> |
| 632 | </pre></div> |
| 633 | </div> |
| 634 | <p>Notice that the equal sign is added for you.</p> |
| 635 | <p>If you use multiple function calls they will be chained together with |
| 636 | AND between them:</p> |
| 637 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'name'</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> |
| 638 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="nv">$title</span><span class="p">);</span> |
| 639 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'status'</span><span class="p">,</span> <span class="nv">$status</span><span class="p">);</span> |
| 640 | <span class="c1">// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'</span> |
| 641 | </pre></div> |
| 642 | </div> |
| 643 | </div></blockquote> |
| 644 | </li> |
| 645 | <li><p class="first"><strong>Custom key/value method:</strong></p> |
| 646 | <blockquote> |
| 647 | <div><p>You can include an operator in the first parameter in order to |
| 648 | control the comparison:</p> |
| 649 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'name !='</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> |
| 650 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id <'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> <span class="c1">// Produces: WHERE name != 'Joe' AND id < 45</span> |
| 651 | </pre></div> |
| 652 | </div> |
| 653 | </div></blockquote> |
| 654 | </li> |
| 655 | <li><p class="first"><strong>Associative array method:</strong></p> |
| 656 | <blockquote> |
| 657 | <div><div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$array</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'name'</span> <span class="o">=></span> <span class="nv">$name</span><span class="p">,</span> <span class="s1">'title'</span> <span class="o">=></span> <span class="nv">$title</span><span class="p">,</span> <span class="s1">'status'</span> <span class="o">=></span> <span class="nv">$status</span><span class="p">);</span> |
| 658 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span> |
| 659 | <span class="c1">// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'</span> |
| 660 | </pre></div> |
| 661 | </div> |
| 662 | <p>You can include your own operators using this method as well:</p> |
| 663 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$array</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'name !='</span> <span class="o">=></span> <span class="nv">$name</span><span class="p">,</span> <span class="s1">'id <'</span> <span class="o">=></span> <span class="nv">$id</span><span class="p">,</span> <span class="s1">'date >'</span> <span class="o">=></span> <span class="nv">$date</span><span class="p">);</span> |
| 664 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span> |
| 665 | </pre></div> |
| 666 | </div> |
| 667 | </div></blockquote> |
| 668 | </li> |
| 669 | <li><dl class="first docutils"> |
| 670 | <dt><strong>Custom string:</strong></dt> |
| 671 | <dd><p class="first">You can write your own clauses manually:</p> |
| 672 | <div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$where</span> <span class="o">=</span> <span class="s2">"name='Joe' AND status='boss' OR status='active'"</span><span class="p">;</span> |
| 673 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="nv">$where</span><span class="p">);</span> |
| 674 | </pre></div> |
| 675 | </div> |
| 676 | </dd> |
| 677 | </dl> |
| 678 | </li> |
| 679 | </ol> |
| 680 | <p><code class="docutils literal"><span class="pre">$this->db->where()</span></code> accepts an optional third parameter. If you set it to |
| 681 | FALSE, CodeIgniter will not try to protect your field or table names.</p> |
| 682 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'MATCH (field) AGAINST ("value")'</span><span class="p">,</span> <span class="k">NULL</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 683 | </pre></div> |
| 684 | </div> |
| 685 | <p><strong>$this->db->or_where()</strong></p> |
| 686 | <p>This function is identical to the one above, except that multiple |
| 687 | instances are joined by OR:</p> |
| 688 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'name !='</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> |
| 689 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">or_where</span><span class="p">(</span><span class="s1">'id >'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> <span class="c1">// Produces: WHERE name != 'Joe' OR id > 50</span> |
| 690 | </pre></div> |
| 691 | </div> |
| 692 | <div class="admonition note"> |
| 693 | <p class="first admonition-title">Note</p> |
| 694 | <p class="last">or_where() was formerly known as orwhere(), which has been |
| 695 | removed.</p> |
| 696 | </div> |
| 697 | <p><strong>$this->db->where_in()</strong></p> |
| 698 | <p>Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with AND if |
| 699 | appropriate</p> |
| 700 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$names</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'Frank'</span><span class="p">,</span> <span class="s1">'Todd'</span><span class="p">,</span> <span class="s1">'James'</span><span class="p">);</span> |
| 701 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where_in</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="nv">$names</span><span class="p">);</span> |
| 702 | <span class="c1">// Produces: WHERE username IN ('Frank', 'Todd', 'James')</span> |
| 703 | </pre></div> |
| 704 | </div> |
| 705 | <p><strong>$this->db->or_where_in()</strong></p> |
| 706 | <p>Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with OR if |
| 707 | appropriate</p> |
| 708 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$names</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'Frank'</span><span class="p">,</span> <span class="s1">'Todd'</span><span class="p">,</span> <span class="s1">'James'</span><span class="p">);</span> |
| 709 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">or_where_in</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="nv">$names</span><span class="p">);</span> |
| 710 | <span class="c1">// Produces: OR username IN ('Frank', 'Todd', 'James')</span> |
| 711 | </pre></div> |
| 712 | </div> |
| 713 | <p><strong>$this->db->where_not_in()</strong></p> |
| 714 | <p>Generates a WHERE field NOT IN (‘item’, ‘item’) SQL query joined with |
| 715 | AND if appropriate</p> |
| 716 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$names</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'Frank'</span><span class="p">,</span> <span class="s1">'Todd'</span><span class="p">,</span> <span class="s1">'James'</span><span class="p">);</span> |
| 717 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where_not_in</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="nv">$names</span><span class="p">);</span> |
| 718 | <span class="c1">// Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')</span> |
| 719 | </pre></div> |
| 720 | </div> |
| 721 | <p><strong>$this->db->or_where_not_in()</strong></p> |
| 722 | <p>Generates a WHERE field NOT IN (‘item’, ‘item’) SQL query joined with OR |
| 723 | if appropriate</p> |
| 724 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$names</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'Frank'</span><span class="p">,</span> <span class="s1">'Todd'</span><span class="p">,</span> <span class="s1">'James'</span><span class="p">);</span> |
| 725 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">or_where_not_in</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="nv">$names</span><span class="p">);</span> |
| 726 | <span class="c1">// Produces: OR username NOT IN ('Frank', 'Todd', 'James')</span> |
| 727 | </pre></div> |
| 728 | </div> |
| 729 | </div> |
| 730 | <div class="section" id="looking-for-similar-data"> |
| 731 | <h2><a class="toc-backref" href="#id3">Looking for Similar Data</a><a class="headerlink" href="#looking-for-similar-data" title="Permalink to this headline">¶</a></h2> |
| 732 | <p><strong>$this->db->like()</strong></p> |
| 733 | <p>This method enables you to generate <strong>LIKE</strong> clauses, useful for doing |
| 734 | searches.</p> |
| 735 | <div class="admonition note"> |
| 736 | <p class="first admonition-title">Note</p> |
| 737 | <p class="last">All values passed to this method are escaped automatically.</p> |
| 738 | </div> |
| 739 | <ol class="arabic"> |
| 740 | <li><p class="first"><strong>Simple key/value method:</strong></p> |
| 741 | <blockquote> |
| 742 | <div><div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 743 | <span class="c1">// Produces: WHERE `title` LIKE '%match%' ESCAPE '!'</span> |
| 744 | </pre></div> |
| 745 | </div> |
| 746 | <p>If you use multiple method calls they will be chained together with |
| 747 | AND between them:</p> |
| 748 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 749 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'body'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 750 | <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' AND `body` LIKE '%match% ESCAPE '!'</span> |
| 751 | </pre></div> |
| 752 | </div> |
| 753 | <p>If you want to control where the wildcard (%) is placed, you can use |
| 754 | an optional third argument. Your options are ‘before’, ‘after’, ‘none’ and |
| 755 | ‘both’ (which is the default).</p> |
| 756 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">,</span> <span class="s1">'before'</span><span class="p">);</span> <span class="c1">// Produces: WHERE `title` LIKE '%match' ESCAPE '!'</span> |
| 757 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">,</span> <span class="s1">'after'</span><span class="p">);</span> <span class="c1">// Produces: WHERE `title` LIKE 'match%' ESCAPE '!'</span> |
| 758 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">,</span> <span class="s1">'none'</span><span class="p">);</span> <span class="c1">// Produces: WHERE `title` LIKE 'match' ESCAPE '!'</span> |
| 759 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">,</span> <span class="s1">'both'</span><span class="p">);</span> <span class="c1">// Produces: WHERE `title` LIKE '%match%' ESCAPE '!'</span> |
| 760 | </pre></div> |
| 761 | </div> |
| 762 | </div></blockquote> |
| 763 | </li> |
| 764 | <li><p class="first"><strong>Associative array method:</strong></p> |
| 765 | <blockquote> |
| 766 | <div><div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$array</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">'title'</span> <span class="o">=></span> <span class="nv">$match</span><span class="p">,</span> <span class="s1">'page1'</span> <span class="o">=></span> <span class="nv">$match</span><span class="p">,</span> <span class="s1">'page2'</span> <span class="o">=></span> <span class="nv">$match</span><span class="p">);</span> |
| 767 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span> |
| 768 | <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' AND `page1` LIKE '%match%' ESCAPE '!' AND `page2` LIKE '%match%' ESCAPE '!'</span> |
| 769 | </pre></div> |
| 770 | </div> |
| 771 | </div></blockquote> |
| 772 | </li> |
| 773 | </ol> |
| 774 | <p><strong>$this->db->or_like()</strong></p> |
| 775 | <p>This method is identical to the one above, except that multiple |
| 776 | instances are joined by OR:</p> |
| 777 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">or_like</span><span class="p">(</span><span class="s1">'body'</span><span class="p">,</span> <span class="nv">$match</span><span class="p">);</span> |
| 778 | <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' OR `body` LIKE '%match%' ESCAPE '!'</span> |
| 779 | </pre></div> |
| 780 | </div> |
| 781 | <div class="admonition note"> |
| 782 | <p class="first admonition-title">Note</p> |
| 783 | <p class="last"><code class="docutils literal"><span class="pre">or_like()</span></code> was formerly known as <code class="docutils literal"><span class="pre">orlike()</span></code>, which has been removed.</p> |
| 784 | </div> |
| 785 | <p><strong>$this->db->not_like()</strong></p> |
| 786 | <p>This method is identical to <code class="docutils literal"><span class="pre">like()</span></code>, except that it generates |
| 787 | NOT LIKE statements:</p> |
| 788 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">not_like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> <span class="c1">// WHERE `title` NOT LIKE '%match% ESCAPE '!'</span> |
| 789 | </pre></div> |
| 790 | </div> |
| 791 | <p><strong>$this->db->or_not_like()</strong></p> |
| 792 | <p>This method is identical to <code class="docutils literal"><span class="pre">not_like()</span></code>, except that multiple |
| 793 | instances are joined by OR:</p> |
| 794 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 795 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">or_not_like</span><span class="p">(</span><span class="s1">'body'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 796 | <span class="c1">// WHERE `title` LIKE '%match% OR `body` NOT LIKE '%match%' ESCAPE '!'</span> |
| 797 | </pre></div> |
| 798 | </div> |
| 799 | <p><strong>$this->db->group_by()</strong></p> |
| 800 | <p>Permits you to write the GROUP BY portion of your query:</p> |
| 801 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">group_by</span><span class="p">(</span><span class="s2">"title"</span><span class="p">);</span> <span class="c1">// Produces: GROUP BY title</span> |
| 802 | </pre></div> |
| 803 | </div> |
| 804 | <p>You can also pass an array of multiple values as well:</p> |
| 805 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">group_by</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s2">"title"</span><span class="p">,</span> <span class="s2">"date"</span><span class="p">));</span> <span class="c1">// Produces: GROUP BY title, date</span> |
| 806 | </pre></div> |
| 807 | </div> |
| 808 | <div class="admonition note"> |
| 809 | <p class="first admonition-title">Note</p> |
| 810 | <p class="last">group_by() was formerly known as groupby(), which has been |
| 811 | removed.</p> |
| 812 | </div> |
| 813 | <p><strong>$this->db->distinct()</strong></p> |
| 814 | <p>Adds the “DISTINCT” keyword to a query</p> |
| 815 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">distinct</span><span class="p">();</span> |
| 816 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">get</span><span class="p">(</span><span class="s1">'table'</span><span class="p">);</span> <span class="c1">// Produces: SELECT DISTINCT * FROM table</span> |
| 817 | </pre></div> |
| 818 | </div> |
| 819 | <p><strong>$this->db->having()</strong></p> |
| 820 | <p>Permits you to write the HAVING portion of your query. There are 2 |
| 821 | possible syntaxes, 1 argument or 2:</p> |
| 822 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">having</span><span class="p">(</span><span class="s1">'user_id = 45'</span><span class="p">);</span> <span class="c1">// Produces: HAVING user_id = 45</span> |
| 823 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">having</span><span class="p">(</span><span class="s1">'user_id'</span><span class="p">,</span> <span class="mi">45</span><span class="p">);</span> <span class="c1">// Produces: HAVING user_id = 45</span> |
| 824 | </pre></div> |
| 825 | </div> |
| 826 | <p>You can also pass an array of multiple values as well:</p> |
| 827 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">having</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'title ='</span> <span class="o">=></span> <span class="s1">'My Title'</span><span class="p">,</span> <span class="s1">'id <'</span> <span class="o">=></span> <span class="nv">$id</span><span class="p">));</span> |
| 828 | <span class="c1">// Produces: HAVING title = 'My Title', id < 45</span> |
| 829 | </pre></div> |
| 830 | </div> |
| 831 | <p>If you are using a database that CodeIgniter escapes queries for, you |
| 832 | can prevent escaping content by passing an optional third argument, and |
| 833 | setting it to FALSE.</p> |
| 834 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">having</span><span class="p">(</span><span class="s1">'user_id'</span><span class="p">,</span> <span class="mi">45</span><span class="p">);</span> <span class="c1">// Produces: HAVING `user_id` = 45 in some databases such as MySQL</span> |
| 835 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">having</span><span class="p">(</span><span class="s1">'user_id'</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> <span class="c1">// Produces: HAVING user_id = 45</span> |
| 836 | </pre></div> |
| 837 | </div> |
| 838 | <p><strong>$this->db->or_having()</strong></p> |
| 839 | <p>Identical to having(), only separates multiple clauses with “OR”.</p> |
| 840 | </div> |
| 841 | <div class="section" id="ordering-results"> |
| 842 | <h2><a class="toc-backref" href="#id4">Ordering results</a><a class="headerlink" href="#ordering-results" title="Permalink to this headline">¶</a></h2> |
| 843 | <p><strong>$this->db->order_by()</strong></p> |
| 844 | <p>Lets you set an ORDER BY clause.</p> |
| 845 | <p>The first parameter contains the name of the column you would like to order by.</p> |
| 846 | <p>The second parameter lets you set the direction of the result. |
| 847 | Options are <strong>ASC</strong>, <strong>DESC</strong> AND <strong>RANDOM</strong>.</p> |
| 848 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'DESC'</span><span class="p">);</span> |
| 849 | <span class="c1">// Produces: ORDER BY `title` DESC</span> |
| 850 | </pre></div> |
| 851 | </div> |
| 852 | <p>You can also pass your own string in the first parameter:</p> |
| 853 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="s1">'title DESC, name ASC'</span><span class="p">);</span> |
| 854 | <span class="c1">// Produces: ORDER BY `title` DESC, `name` ASC</span> |
| 855 | </pre></div> |
| 856 | </div> |
| 857 | <p>Or multiple function calls can be made if you need multiple fields.</p> |
| 858 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'DESC'</span><span class="p">);</span> |
| 859 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="s1">'name'</span><span class="p">,</span> <span class="s1">'ASC'</span><span class="p">);</span> |
| 860 | <span class="c1">// Produces: ORDER BY `title` DESC, `name` ASC</span> |
| 861 | </pre></div> |
| 862 | </div> |
| 863 | <p>If you choose the <strong>RANDOM</strong> direction option, then the first parameters will |
| 864 | be ignored, unless you specify a numeric seed value.</p> |
| 865 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'RANDOM'</span><span class="p">);</span> |
| 866 | <span class="c1">// Produces: ORDER BY RAND()</span> |
| 867 | |
| 868 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">order_by</span><span class="p">(</span><span class="mi">42</span><span class="p">,</span> <span class="s1">'RANDOM'</span><span class="p">);</span> |
| 869 | <span class="c1">// Produces: ORDER BY RAND(42)</span> |
| 870 | </pre></div> |
| 871 | </div> |
| 872 | <div class="admonition note"> |
| 873 | <p class="first admonition-title">Note</p> |
| 874 | <p class="last">order_by() was formerly known as orderby(), which has been |
| 875 | removed.</p> |
| 876 | </div> |
| 877 | <div class="admonition note"> |
| 878 | <p class="first admonition-title">Note</p> |
| 879 | <p class="last">Random ordering is not currently supported in Oracle and |
| 880 | will default to ASC instead.</p> |
| 881 | </div> |
| 882 | </div> |
| 883 | <div class="section" id="limiting-or-counting-results"> |
| 884 | <h2><a class="toc-backref" href="#id5">Limiting or Counting Results</a><a class="headerlink" href="#limiting-or-counting-results" title="Permalink to this headline">¶</a></h2> |
| 885 | <p><strong>$this->db->limit()</strong></p> |
| 886 | <p>Lets you limit the number of rows you would like returned by the query:</p> |
| 887 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">limit</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span> <span class="c1">// Produces: LIMIT 10</span> |
| 888 | </pre></div> |
| 889 | </div> |
| 890 | <p>The second parameter lets you set a result offset.</p> |
| 891 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">limit</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">);</span> <span class="c1">// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)</span> |
| 892 | </pre></div> |
| 893 | </div> |
| 894 | <p><strong>$this->db->count_all_results()</strong></p> |
| 895 | <p>Permits you to determine the number of rows in a particular Active |
| 896 | Record query. Queries will accept Query Builder restrictors such as |
| 897 | <code class="docutils literal"><span class="pre">where()</span></code>, <code class="docutils literal"><span class="pre">or_where()</span></code>, <code class="docutils literal"><span class="pre">like()</span></code>, <code class="docutils literal"><span class="pre">or_like()</span></code>, etc. Example:</p> |
| 898 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">count_all_results</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">);</span> <span class="c1">// Produces an integer, like 25</span> |
| 899 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">like</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span> |
| 900 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">from</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">);</span> |
| 901 | <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">count_all_results</span><span class="p">();</span> <span class="c1">// Produces an integer, like 17</span> |
| 902 | </pre></div> |
| 903 | </div> |
| 904 | <p>However, this method also resets any field values that you may have passed |
| 905 | to <code class="docutils literal"><span class="pre">select()</span></code>. If you need to keep them, you can pass <code class="docutils literal"><span class="pre">FALSE</span></code> as the |
| 906 | second parameter:</p> |
| 907 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">count_all_results</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 908 | </pre></div> |
| 909 | </div> |
| 910 | <p><strong>$this->db->count_all()</strong></p> |
| 911 | <p>Permits you to determine the number of rows in a particular table. |
| 912 | Submit the table name in the first parameter. Example:</p> |
| 913 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">count_all</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">);</span> <span class="c1">// Produces an integer, like 25</span> |
| 914 | </pre></div> |
| 915 | </div> |
| 916 | </div> |
| 917 | <div class="section" id="query-grouping"> |
| 918 | <h2><a class="toc-backref" href="#id6">Query grouping</a><a class="headerlink" href="#query-grouping" title="Permalink to this headline">¶</a></h2> |
| 919 | <p>Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow |
| 920 | you to create queries with complex WHERE clauses. Nested groups are supported. Example:</p> |
| 921 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'*'</span><span class="p">)</span><span class="o">-></span><span class="na">from</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">)</span> |
| 922 | <span class="o">-></span><span class="na">group_start</span><span class="p">()</span> |
| 923 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'a'</span><span class="p">,</span> <span class="s1">'a'</span><span class="p">)</span> |
| 924 | <span class="o">-></span><span class="na">or_group_start</span><span class="p">()</span> |
| 925 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'b'</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">)</span> |
| 926 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'c'</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">)</span> |
| 927 | <span class="o">-></span><span class="na">group_end</span><span class="p">()</span> |
| 928 | <span class="o">-></span><span class="na">group_end</span><span class="p">()</span> |
| 929 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'d'</span><span class="p">,</span> <span class="s1">'d'</span><span class="p">)</span> |
| 930 | <span class="o">-></span><span class="na">get</span><span class="p">();</span> |
| 931 | |
| 932 | <span class="c1">// Generates:</span> |
| 933 | <span class="c1">// SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'</span> |
| 934 | </pre></div> |
| 935 | </div> |
| 936 | <div class="admonition note"> |
| 937 | <p class="first admonition-title">Note</p> |
| 938 | <p class="last">groups need to be balanced, make sure every group_start() is matched by a group_end().</p> |
| 939 | </div> |
| 940 | <p><strong>$this->db->group_start()</strong></p> |
| 941 | <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query.</p> |
| 942 | <p><strong>$this->db->or_group_start()</strong></p> |
| 943 | <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘OR’.</p> |
| 944 | <p><strong>$this->db->not_group_start()</strong></p> |
| 945 | <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘NOT’.</p> |
| 946 | <p><strong>$this->db->or_not_group_start()</strong></p> |
| 947 | <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘OR NOT’.</p> |
| 948 | <p><strong>$this->db->group_end()</strong></p> |
| 949 | <p>Ends the current group by adding an closing parenthesis to the WHERE clause of the query.</p> |
| 950 | </div> |
| 951 | <div class="section" id="inserting-data"> |
| 952 | <h2><a class="toc-backref" href="#id7">Inserting Data</a><a class="headerlink" href="#inserting-data" title="Permalink to this headline">¶</a></h2> |
| 953 | <p><strong>$this->db->insert()</strong></p> |
| 954 | <p>Generates an insert string based on the data you supply, and runs the |
| 955 | query. You can either pass an <strong>array</strong> or an <strong>object</strong> to the |
| 956 | function. Here is an example using an array:</p> |
| 957 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 958 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span> |
| 959 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span> |
| 960 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</span> |
| 961 | <span class="p">);</span> |
| 962 | |
| 963 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span> |
| 964 | <span class="c1">// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')</span> |
| 965 | </pre></div> |
| 966 | </div> |
| 967 | <p>The first parameter will contain the table name, the second is an |
| 968 | associative array of values.</p> |
| 969 | <p>Here is an example using an object:</p> |
| 970 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span> |
| 971 | <span class="cm">class Myclass {</span> |
| 972 | <span class="cm"> public $title = 'My Title';</span> |
| 973 | <span class="cm"> public $content = 'My Content';</span> |
| 974 | <span class="cm"> public $date = 'My Date';</span> |
| 975 | <span class="cm">}</span> |
| 976 | <span class="cm">*/</span> |
| 977 | |
| 978 | <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</span><span class="p">;</span> |
| 979 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$object</span><span class="p">);</span> |
| 980 | <span class="c1">// Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')</span> |
| 981 | </pre></div> |
| 982 | </div> |
| 983 | <p>The first parameter will contain the table name, the second is an |
| 984 | object.</p> |
| 985 | <div class="admonition note"> |
| 986 | <p class="first admonition-title">Note</p> |
| 987 | <p class="last">All values are escaped automatically producing safer queries.</p> |
| 988 | </div> |
| 989 | <p><strong>$this->db->get_compiled_insert()</strong></p> |
| 990 | <p>Compiles the insertion query just like $this->db->insert() but does not |
| 991 | <em>run</em> the query. This method simply returns the SQL query as a string.</p> |
| 992 | <p>Example:</p> |
| 993 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 994 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span> |
| 995 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span> |
| 996 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</span> |
| 997 | <span class="p">);</span> |
| 998 | |
| 999 | <span class="nv">$sql</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">set</span><span class="p">(</span><span class="nv">$data</span><span class="p">)</span><span class="o">-></span><span class="na">get_compiled_insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1000 | <span class="k">echo</span> <span class="nv">$sql</span><span class="p">;</span> |
| 1001 | |
| 1002 | <span class="c1">// Produces string: INSERT INTO mytable (`title`, `name`, `date`) VALUES ('My title', 'My name', 'My date')</span> |
| 1003 | </pre></div> |
| 1004 | </div> |
| 1005 | <p>The second parameter enables you to set whether or not the query builder query |
| 1006 | will be reset (by default it will be–just like $this->db->insert()):</p> |
| 1007 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="s1">'My Title'</span><span class="p">)</span><span class="o">-></span><span class="na">get_compiled_insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 1008 | |
| 1009 | <span class="c1">// Produces string: INSERT INTO mytable (`title`) VALUES ('My Title')</span> |
| 1010 | |
| 1011 | <span class="k">echo</span> <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'content'</span><span class="p">,</span> <span class="s1">'My Content'</span><span class="p">)</span><span class="o">-></span><span class="na">get_compiled_insert</span><span class="p">();</span> |
| 1012 | |
| 1013 | <span class="c1">// Produces string: INSERT INTO mytable (`title`, `content`) VALUES ('My Title', 'My Content')</span> |
| 1014 | </pre></div> |
| 1015 | </div> |
| 1016 | <p>The key thing to notice in the above example is that the second query did not |
| 1017 | utilize <cite>$this->db->from()</cite> nor did it pass a table name into the first |
| 1018 | parameter. The reason this worked is because the query has not been executed |
| 1019 | using <cite>$this->db->insert()</cite> which resets values or reset directly using |
| 1020 | <cite>$this->db->reset_query()</cite>.</p> |
| 1021 | <div class="admonition note"> |
| 1022 | <p class="first admonition-title">Note</p> |
| 1023 | <p class="last">This method doesn’t work for batched inserts.</p> |
| 1024 | </div> |
| 1025 | <p><strong>$this->db->insert_batch()</strong></p> |
| 1026 | <p>Generates an insert string based on the data you supply, and runs the |
| 1027 | query. You can either pass an <strong>array</strong> or an <strong>object</strong> to the |
| 1028 | function. Here is an example using an array:</p> |
| 1029 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 1030 | <span class="k">array</span><span class="p">(</span> |
| 1031 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span> |
| 1032 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span> |
| 1033 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</span> |
| 1034 | <span class="p">),</span> |
| 1035 | <span class="k">array</span><span class="p">(</span> |
| 1036 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'Another title'</span><span class="p">,</span> |
| 1037 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'Another Name'</span><span class="p">,</span> |
| 1038 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'Another date'</span> |
| 1039 | <span class="p">)</span> |
| 1040 | <span class="p">);</span> |
| 1041 | |
| 1042 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert_batch</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span> |
| 1043 | <span class="c1">// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')</span> |
| 1044 | </pre></div> |
| 1045 | </div> |
| 1046 | <p>The first parameter will contain the table name, the second is an |
| 1047 | associative array of values.</p> |
| 1048 | <div class="admonition note"> |
| 1049 | <p class="first admonition-title">Note</p> |
| 1050 | <p class="last">All values are escaped automatically producing safer queries.</p> |
| 1051 | </div> |
| 1052 | </div> |
| 1053 | <div class="section" id="updating-data"> |
| 1054 | <h2><a class="toc-backref" href="#id8">Updating Data</a><a class="headerlink" href="#updating-data" title="Permalink to this headline">¶</a></h2> |
| 1055 | <p><strong>$this->db->replace()</strong></p> |
| 1056 | <p>This method executes a REPLACE statement, which is basically the SQL |
| 1057 | standard for (optional) DELETE + INSERT, using <em>PRIMARY</em> and <em>UNIQUE</em> |
| 1058 | keys as the determining factor. |
| 1059 | In our case, it will save you from the need to implement complex |
| 1060 | logics with different combinations of <code class="docutils literal"><span class="pre">select()</span></code>, <code class="docutils literal"><span class="pre">update()</span></code>, |
| 1061 | <code class="docutils literal"><span class="pre">delete()</span></code> and <code class="docutils literal"><span class="pre">insert()</span></code> calls.</p> |
| 1062 | <p>Example:</p> |
| 1063 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 1064 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span> |
| 1065 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span> |
| 1066 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</span> |
| 1067 | <span class="p">);</span> |
| 1068 | |
| 1069 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">replace</span><span class="p">(</span><span class="s1">'table'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span> |
| 1070 | |
| 1071 | <span class="c1">// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')</span> |
| 1072 | </pre></div> |
| 1073 | </div> |
| 1074 | <p>In the above example, if we assume that the <em>title</em> field is our primary |
| 1075 | key, then if a row containing ‘My title’ as the <em>title</em> value, that row |
| 1076 | will be deleted with our new row data replacing it.</p> |
| 1077 | <p>Usage of the <code class="docutils literal"><span class="pre">set()</span></code> method is also allowed and all fields are |
| 1078 | automatically escaped, just like with <code class="docutils literal"><span class="pre">insert()</span></code>.</p> |
| 1079 | <p><strong>$this->db->set()</strong></p> |
| 1080 | <p>This function enables you to set values for inserts or updates.</p> |
| 1081 | <p><strong>It can be used instead of passing a data array directly to the insert |
| 1082 | or update functions:</strong></p> |
| 1083 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'name'</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> |
| 1084 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> <span class="c1">// Produces: INSERT INTO mytable (`name`) VALUES ('{$name}')</span> |
| 1085 | </pre></div> |
| 1086 | </div> |
| 1087 | <p>If you use multiple function called they will be assembled properly |
| 1088 | based on whether you are doing an insert or an update:</p> |
| 1089 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'name'</span><span class="p">,</span> <span class="nv">$name</span><span class="p">);</span> |
| 1090 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'title'</span><span class="p">,</span> <span class="nv">$title</span><span class="p">);</span> |
| 1091 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'status'</span><span class="p">,</span> <span class="nv">$status</span><span class="p">);</span> |
| 1092 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1093 | </pre></div> |
| 1094 | </div> |
| 1095 | <p><strong>set()</strong> will also accept an optional third parameter (<code class="docutils literal"><span class="pre">$escape</span></code>), that |
| 1096 | will prevent data from being escaped if set to FALSE. To illustrate the |
| 1097 | difference, here is <code class="docutils literal"><span class="pre">set()</span></code> used both with and without the escape |
| 1098 | parameter.</p> |
| 1099 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'field'</span><span class="p">,</span> <span class="s1">'field+1'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 1100 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> |
| 1101 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> <span class="c1">// gives UPDATE mytable SET field = field+1 WHERE id = 2</span> |
| 1102 | |
| 1103 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="s1">'field'</span><span class="p">,</span> <span class="s1">'field+1'</span><span class="p">);</span> |
| 1104 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> |
| 1105 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> <span class="c1">// gives UPDATE `mytable` SET `field` = 'field+1' WHERE `id` = 2</span> |
| 1106 | </pre></div> |
| 1107 | </div> |
| 1108 | <p>You can also pass an associative array to this function:</p> |
| 1109 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$array</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 1110 | <span class="s1">'name'</span> <span class="o">=></span> <span class="nv">$name</span><span class="p">,</span> |
| 1111 | <span class="s1">'title'</span> <span class="o">=></span> <span class="nv">$title</span><span class="p">,</span> |
| 1112 | <span class="s1">'status'</span> <span class="o">=></span> <span class="nv">$status</span> |
| 1113 | <span class="p">);</span> |
| 1114 | |
| 1115 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="nv">$array</span><span class="p">);</span> |
| 1116 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1117 | </pre></div> |
| 1118 | </div> |
| 1119 | <p>Or an object:</p> |
| 1120 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span> |
| 1121 | <span class="cm">class Myclass {</span> |
| 1122 | <span class="cm"> public $title = 'My Title';</span> |
| 1123 | <span class="cm"> public $content = 'My Content';</span> |
| 1124 | <span class="cm"> public $date = 'My Date';</span> |
| 1125 | <span class="cm">}</span> |
| 1126 | <span class="cm">*/</span> |
| 1127 | |
| 1128 | <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</span><span class="p">;</span> |
| 1129 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">set</span><span class="p">(</span><span class="nv">$object</span><span class="p">);</span> |
| 1130 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1131 | </pre></div> |
| 1132 | </div> |
| 1133 | <p><strong>$this->db->update()</strong></p> |
| 1134 | <p>Generates an update string and runs the query based on the data you |
| 1135 | supply. You can pass an <strong>array</strong> or an <strong>object</strong> to the function. Here |
| 1136 | is an example using an array:</p> |
| 1137 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 1138 | <span class="s1">'title'</span> <span class="o">=></span> <span class="nv">$title</span><span class="p">,</span> |
| 1139 | <span class="s1">'name'</span> <span class="o">=></span> <span class="nv">$name</span><span class="p">,</span> |
| 1140 | <span class="s1">'date'</span> <span class="o">=></span> <span class="nv">$date</span> |
| 1141 | <span class="p">);</span> |
| 1142 | |
| 1143 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> |
| 1144 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span> |
| 1145 | <span class="c1">// Produces:</span> |
| 1146 | <span class="c1">//</span> |
| 1147 | <span class="c1">// UPDATE mytable</span> |
| 1148 | <span class="c1">// SET title = '{$title}', name = '{$name}', date = '{$date}'</span> |
| 1149 | <span class="c1">// WHERE id = $id</span> |
| 1150 | </pre></div> |
| 1151 | </div> |
| 1152 | <p>Or you can supply an object:</p> |
| 1153 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span> |
| 1154 | <span class="cm">class Myclass {</span> |
| 1155 | <span class="cm"> public $title = 'My Title';</span> |
| 1156 | <span class="cm"> public $content = 'My Content';</span> |
| 1157 | <span class="cm"> public $date = 'My Date';</span> |
| 1158 | <span class="cm">}</span> |
| 1159 | <span class="cm">*/</span> |
| 1160 | |
| 1161 | <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</span><span class="p">;</span> |
| 1162 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> |
| 1163 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$object</span><span class="p">);</span> |
| 1164 | <span class="c1">// Produces:</span> |
| 1165 | <span class="c1">//</span> |
| 1166 | <span class="c1">// UPDATE `mytable`</span> |
| 1167 | <span class="c1">// SET `title` = '{$title}', `name` = '{$name}', `date` = '{$date}'</span> |
| 1168 | <span class="c1">// WHERE id = `$id`</span> |
| 1169 | </pre></div> |
| 1170 | </div> |
| 1171 | <div class="admonition note"> |
| 1172 | <p class="first admonition-title">Note</p> |
| 1173 | <p class="last">All values are escaped automatically producing safer queries.</p> |
| 1174 | </div> |
| 1175 | <p>You’ll notice the use of the $this->db->where() function, enabling you |
| 1176 | to set the WHERE clause. You can optionally pass this information |
| 1177 | directly into the update function as a string:</p> |
| 1178 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">,</span> <span class="s2">"id = 4"</span><span class="p">);</span> |
| 1179 | </pre></div> |
| 1180 | </div> |
| 1181 | <p>Or as an array:</p> |
| 1182 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">'id'</span> <span class="o">=></span> <span class="nv">$id</span><span class="p">));</span> |
| 1183 | </pre></div> |
| 1184 | </div> |
| 1185 | <p>You may also use the $this->db->set() function described above when |
| 1186 | performing updates.</p> |
| 1187 | <p><strong>$this->db->update_batch()</strong></p> |
| 1188 | <p>Generates an update string based on the data you supply, and runs the query. |
| 1189 | You can either pass an <strong>array</strong> or an <strong>object</strong> to the function. |
| 1190 | Here is an example using an array:</p> |
| 1191 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> |
| 1192 | <span class="k">array</span><span class="p">(</span> |
| 1193 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span> <span class="p">,</span> |
| 1194 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name 2'</span> <span class="p">,</span> |
| 1195 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date 2'</span> |
| 1196 | <span class="p">),</span> |
| 1197 | <span class="k">array</span><span class="p">(</span> |
| 1198 | <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'Another title'</span> <span class="p">,</span> |
| 1199 | <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'Another Name 2'</span> <span class="p">,</span> |
| 1200 | <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'Another date 2'</span> |
| 1201 | <span class="p">)</span> |
| 1202 | <span class="p">);</span> |
| 1203 | |
| 1204 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">update_batch</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">,</span> <span class="s1">'title'</span><span class="p">);</span> |
| 1205 | |
| 1206 | <span class="c1">// Produces:</span> |
| 1207 | <span class="c1">// UPDATE `mytable` SET `name` = CASE</span> |
| 1208 | <span class="c1">// WHEN `title` = 'My title' THEN 'My Name 2'</span> |
| 1209 | <span class="c1">// WHEN `title` = 'Another title' THEN 'Another Name 2'</span> |
| 1210 | <span class="c1">// ELSE `name` END,</span> |
| 1211 | <span class="c1">// `date` = CASE</span> |
| 1212 | <span class="c1">// WHEN `title` = 'My title' THEN 'My date 2'</span> |
| 1213 | <span class="c1">// WHEN `title` = 'Another title' THEN 'Another date 2'</span> |
| 1214 | <span class="c1">// ELSE `date` END</span> |
| 1215 | <span class="c1">// WHERE `title` IN ('My title','Another title')</span> |
| 1216 | </pre></div> |
| 1217 | </div> |
| 1218 | <p>The first parameter will contain the table name, the second is an associative |
| 1219 | array of values, the third parameter is the where key.</p> |
| 1220 | <div class="admonition note"> |
| 1221 | <p class="first admonition-title">Note</p> |
| 1222 | <p class="last">All values are escaped automatically producing safer queries.</p> |
| 1223 | </div> |
| 1224 | <div class="admonition note"> |
| 1225 | <p class="first admonition-title">Note</p> |
| 1226 | <p class="last"><code class="docutils literal"><span class="pre">affected_rows()</span></code> won’t give you proper results with this method, |
| 1227 | due to the very nature of how it works. Instead, <code class="docutils literal"><span class="pre">update_batch()</span></code> |
| 1228 | returns the number of rows affected.</p> |
| 1229 | </div> |
| 1230 | <p><strong>$this->db->get_compiled_update()</strong></p> |
| 1231 | <p>This works exactly the same way as <code class="docutils literal"><span class="pre">$this->db->get_compiled_insert()</span></code> except |
| 1232 | that it produces an UPDATE SQL string instead of an INSERT SQL string.</p> |
| 1233 | <p>For more information view documentation for <cite>$this->db->get_compiled_insert()</cite>.</p> |
| 1234 | <div class="admonition note"> |
| 1235 | <p class="first admonition-title">Note</p> |
| 1236 | <p class="last">This method doesn’t work for batched updates.</p> |
| 1237 | </div> |
| 1238 | </div> |
| 1239 | <div class="section" id="deleting-data"> |
| 1240 | <h2><a class="toc-backref" href="#id9">Deleting Data</a><a class="headerlink" href="#deleting-data" title="Permalink to this headline">¶</a></h2> |
| 1241 | <p><strong>$this->db->delete()</strong></p> |
| 1242 | <p>Generates a delete SQL string and runs the query.</p> |
| 1243 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">delete</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">'id'</span> <span class="o">=></span> <span class="nv">$id</span><span class="p">));</span> <span class="c1">// Produces: // DELETE FROM mytable // WHERE id = $id</span> |
| 1244 | </pre></div> |
| 1245 | </div> |
| 1246 | <p>The first parameter is the table name, the second is the where clause. |
| 1247 | You can also use the where() or or_where() functions instead of passing |
| 1248 | the data to the second parameter of the function:</p> |
| 1249 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">);</span> |
| 1250 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">delete</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1251 | |
| 1252 | <span class="c1">// Produces:</span> |
| 1253 | <span class="c1">// DELETE FROM mytable</span> |
| 1254 | <span class="c1">// WHERE id = $id</span> |
| 1255 | </pre></div> |
| 1256 | </div> |
| 1257 | <p>An array of table names can be passed into delete() if you would like to |
| 1258 | delete data from more than 1 table.</p> |
| 1259 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$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="s1">'table3'</span><span class="p">);</span> |
| 1260 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="s1">'5'</span><span class="p">);</span> |
| 1261 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">delete</span><span class="p">(</span><span class="nv">$tables</span><span class="p">);</span> |
| 1262 | </pre></div> |
| 1263 | </div> |
| 1264 | <p>If you want to delete all data from a table, you can use the truncate() |
| 1265 | function, or empty_table().</p> |
| 1266 | <p><strong>$this->db->empty_table()</strong></p> |
| 1267 | <p>Generates a delete SQL string and runs the |
| 1268 | query.:</p> |
| 1269 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">empty_table</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> <span class="c1">// Produces: DELETE FROM mytable</span> |
| 1270 | </pre></div> |
| 1271 | </div> |
| 1272 | <p><strong>$this->db->truncate()</strong></p> |
| 1273 | <p>Generates a truncate SQL string and runs the query.</p> |
| 1274 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">from</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1275 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">truncate</span><span class="p">();</span> |
| 1276 | |
| 1277 | <span class="c1">// or</span> |
| 1278 | |
| 1279 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">truncate</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1280 | |
| 1281 | <span class="c1">// Produce:</span> |
| 1282 | <span class="c1">// TRUNCATE mytable</span> |
| 1283 | </pre></div> |
| 1284 | </div> |
| 1285 | <div class="admonition note"> |
| 1286 | <p class="first admonition-title">Note</p> |
| 1287 | <p class="last">If the TRUNCATE command isn’t available, truncate() will |
| 1288 | execute as “DELETE FROM table”.</p> |
| 1289 | </div> |
| 1290 | <p><strong>$this->db->get_compiled_delete()</strong></p> |
| 1291 | <p>This works exactly the same way as <code class="docutils literal"><span class="pre">$this->db->get_compiled_insert()</span></code> except |
| 1292 | that it produces a DELETE SQL string instead of an INSERT SQL string.</p> |
| 1293 | <p>For more information view documentation for $this->db->get_compiled_insert().</p> |
| 1294 | </div> |
| 1295 | <div class="section" id="method-chaining"> |
| 1296 | <h2><a class="toc-backref" href="#id10">Method Chaining</a><a class="headerlink" href="#method-chaining" title="Permalink to this headline">¶</a></h2> |
| 1297 | <p>Method chaining allows you to simplify your syntax by connecting |
| 1298 | multiple functions. Consider this example:</p> |
| 1299 | <div class="highlight-ci"><div class="highlight"><pre><span></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">select</span><span class="p">(</span><span class="s1">'title'</span><span class="p">)</span> |
| 1300 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'id'</span><span class="p">,</span> <span class="nv">$id</span><span class="p">)</span> |
| 1301 | <span class="o">-></span><span class="na">limit</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span> |
| 1302 | <span class="o">-></span><span class="na">get</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span> |
| 1303 | </pre></div> |
| 1304 | </div> |
| 1305 | </div> |
| 1306 | <div class="section" id="query-builder-caching"> |
| 1307 | <span id="ar-caching"></span><h2><a class="toc-backref" href="#id11">Query Builder Caching</a><a class="headerlink" href="#query-builder-caching" title="Permalink to this headline">¶</a></h2> |
| 1308 | <p>While not “true” caching, Query Builder enables you to save (or “cache”) |
| 1309 | certain parts of your queries for reuse at a later point in your |
| 1310 | script’s execution. Normally, when an Query Builder call is completed, |
| 1311 | all stored information is reset for the next call. With caching, you can |
| 1312 | prevent this reset, and reuse information easily.</p> |
| 1313 | <p>Cached calls are cumulative. If you make 2 cached select() calls, and |
| 1314 | then 2 uncached select() calls, this will result in 4 select() calls. |
| 1315 | There are three Caching functions available:</p> |
| 1316 | <p><strong>$this->db->start_cache()</strong></p> |
| 1317 | <p>This function must be called to begin caching. All Query Builder queries |
| 1318 | of the correct type (see below for supported queries) are stored for |
| 1319 | later use.</p> |
| 1320 | <p><strong>$this->db->stop_cache()</strong></p> |
| 1321 | <p>This function can be called to stop caching.</p> |
| 1322 | <p><strong>$this->db->flush_cache()</strong></p> |
| 1323 | <p>This function deletes all items from the Query Builder cache.</p> |
| 1324 | <div class="section" id="an-example-of-caching"> |
| 1325 | <h3>An example of caching<a class="headerlink" href="#an-example-of-caching" title="Permalink to this headline">¶</a></h3> |
| 1326 | <p>Here’s a usage example:</p> |
| 1327 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">start_cache</span><span class="p">();</span> |
| 1328 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'field1'</span><span class="p">);</span> |
| 1329 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">stop_cache</span><span class="p">();</span> |
| 1330 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">get</span><span class="p">(</span><span class="s1">'tablename'</span><span class="p">);</span> |
| 1331 | <span class="c1">//Generates: SELECT `field1` FROM (`tablename`)</span> |
| 1332 | |
| 1333 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'field2'</span><span class="p">);</span> |
| 1334 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">get</span><span class="p">(</span><span class="s1">'tablename'</span><span class="p">);</span> |
| 1335 | <span class="c1">//Generates: SELECT `field1`, `field2` FROM (`tablename`)</span> |
| 1336 | |
| 1337 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">flush_cache</span><span class="p">();</span> |
| 1338 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">select</span><span class="p">(</span><span class="s1">'field2'</span><span class="p">);</span> |
| 1339 | <span class="nv">$this</span><span class="o">-></span><span class="na">db</span><span class="o">-></span><span class="na">get</span><span class="p">(</span><span class="s1">'tablename'</span><span class="p">);</span> |
| 1340 | <span class="c1">//Generates: SELECT `field2` FROM (`tablename`)</span> |
| 1341 | </pre></div> |
| 1342 | </div> |
| 1343 | <div class="admonition note"> |
| 1344 | <p class="first admonition-title">Note</p> |
| 1345 | <p class="last">The following statements can be cached: select, from, join, |
| 1346 | where, like, group_by, having, order_by</p> |
| 1347 | </div> |
| 1348 | </div> |
| 1349 | </div> |
| 1350 | <div class="section" id="resetting-query-builder"> |
| 1351 | <h2><a class="toc-backref" href="#id12">Resetting Query Builder</a><a class="headerlink" href="#resetting-query-builder" title="Permalink to this headline">¶</a></h2> |
| 1352 | <p><strong>$this->db->reset_query()</strong></p> |
| 1353 | <p>Resetting Query Builder allows you to start fresh with your query without |
| 1354 | executing it first using a method like $this->db->get() or $this->db->insert(). |
| 1355 | Just like the methods that execute a query, this will <em>not</em> reset items you’ve |
| 1356 | cached using <a class="reference internal" href="#query-builder-caching">Query Builder Caching</a>.</p> |
| 1357 | <p>This is useful in situations where you are using Query Builder to generate SQL |
| 1358 | (ex. <code class="docutils literal"><span class="pre">$this->db->get_compiled_select()</span></code>) but then choose to, for instance, |
| 1359 | run the query:</p> |
| 1360 | <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Note that the second parameter of the get_compiled_select method is FALSE</span> |
| 1361 | <span class="nv">$sql</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">select</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'field1'</span><span class="p">,</span><span class="s1">'field2'</span><span class="p">))</span> |
| 1362 | <span class="o">-></span><span class="na">where</span><span class="p">(</span><span class="s1">'field3'</span><span class="p">,</span><span class="mi">5</span><span class="p">)</span> |
| 1363 | <span class="o">-></span><span class="na">get_compiled_select</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">);</span> |
| 1364 | |
| 1365 | <span class="c1">// ...</span> |
| 1366 | <span class="c1">// Do something crazy with the SQL code... like add it to a cron script for</span> |
| 1367 | <span class="c1">// later execution or something...</span> |
| 1368 | <span class="c1">// ...</span> |
| 1369 | |
| 1370 | <span class="nv">$data</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">get</span><span class="p">()</span><span class="o">-></span><span class="na">result_array</span><span class="p">();</span> |
| 1371 | |
| 1372 | <span class="c1">// Would execute and return an array of results of the following query:</span> |
| 1373 | <span class="c1">// SELECT field1, field1 from mytable where field3 = 5;</span> |
| 1374 | </pre></div> |
| 1375 | </div> |
| 1376 | <div class="admonition note"> |
| 1377 | <p class="first admonition-title">Note</p> |
| 1378 | <p class="last">Double calls to <code class="docutils literal"><span class="pre">get_compiled_select()</span></code> while you’re using the |
| 1379 | Query Builder Caching functionality and NOT resetting your queries |
| 1380 | will results in the cache being merged twice. That in turn will |
| 1381 | i.e. if you’re caching a <code class="docutils literal"><span class="pre">select()</span></code> - select the same field twice.</p> |
| 1382 | </div> |
| 1383 | </div> |
| 1384 | <div class="section" id="class-reference"> |
| 1385 | <h2><a class="toc-backref" href="#id13">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2> |
| 1386 | <dl class="class"> |
| 1387 | <dt id="CI_DB_query_builder"> |
| 1388 | <em class="property">class </em><code class="descname">CI_DB_query_builder</code><a class="headerlink" href="#CI_DB_query_builder" title="Permalink to this definition">¶</a></dt> |
| 1389 | <dd><dl class="method"> |
| 1390 | <dt id="CI_DB_query_builder::reset_query"> |
| 1391 | <code class="descname">reset_query</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::reset_query" title="Permalink to this definition">¶</a></dt> |
| 1392 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1393 | <col class="field-name" /> |
| 1394 | <col class="field-body" /> |
| 1395 | <tbody valign="top"> |
| 1396 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1397 | </tr> |
| 1398 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1399 | </tr> |
| 1400 | </tbody> |
| 1401 | </table> |
| 1402 | <p>Resets the current Query Builder state. Useful when you want |
| 1403 | to build a query that can be cancelled under certain conditions.</p> |
| 1404 | </dd></dl> |
| 1405 | |
| 1406 | <dl class="method"> |
| 1407 | <dt id="CI_DB_query_builder::start_cache"> |
| 1408 | <code class="descname">start_cache</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::start_cache" title="Permalink to this definition">¶</a></dt> |
| 1409 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1410 | <col class="field-name" /> |
| 1411 | <col class="field-body" /> |
| 1412 | <tbody valign="top"> |
| 1413 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1414 | </tr> |
| 1415 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1416 | </tr> |
| 1417 | </tbody> |
| 1418 | </table> |
| 1419 | <p>Starts the Query Builder cache.</p> |
| 1420 | </dd></dl> |
| 1421 | |
| 1422 | <dl class="method"> |
| 1423 | <dt id="CI_DB_query_builder::stop_cache"> |
| 1424 | <code class="descname">stop_cache</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::stop_cache" title="Permalink to this definition">¶</a></dt> |
| 1425 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1426 | <col class="field-name" /> |
| 1427 | <col class="field-body" /> |
| 1428 | <tbody valign="top"> |
| 1429 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1430 | </tr> |
| 1431 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1432 | </tr> |
| 1433 | </tbody> |
| 1434 | </table> |
| 1435 | <p>Stops the Query Builder cache.</p> |
| 1436 | </dd></dl> |
| 1437 | |
| 1438 | <dl class="method"> |
| 1439 | <dt id="CI_DB_query_builder::flush_cache"> |
| 1440 | <code class="descname">flush_cache</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::flush_cache" title="Permalink to this definition">¶</a></dt> |
| 1441 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1442 | <col class="field-name" /> |
| 1443 | <col class="field-body" /> |
| 1444 | <tbody valign="top"> |
| 1445 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1446 | </tr> |
| 1447 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1448 | </tr> |
| 1449 | </tbody> |
| 1450 | </table> |
| 1451 | <p>Empties the Query Builder cache.</p> |
| 1452 | </dd></dl> |
| 1453 | |
| 1454 | <dl class="method"> |
| 1455 | <dt id="CI_DB_query_builder::set_dbprefix"> |
| 1456 | <code class="descname">set_dbprefix</code><span class="sig-paren">(</span><span class="optional">[</span><em>$prefix = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::set_dbprefix" title="Permalink to this definition">¶</a></dt> |
| 1457 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1458 | <col class="field-name" /> |
| 1459 | <col class="field-body" /> |
| 1460 | <tbody valign="top"> |
| 1461 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1462 | <li><strong>$prefix</strong> (<em>string</em>) – The new prefix to use</li> |
| 1463 | </ul> |
| 1464 | </td> |
| 1465 | </tr> |
| 1466 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The DB prefix in use</p> |
| 1467 | </td> |
| 1468 | </tr> |
| 1469 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1470 | </td> |
| 1471 | </tr> |
| 1472 | </tbody> |
| 1473 | </table> |
| 1474 | <p>Sets the database prefix, without having to reconnect.</p> |
| 1475 | </dd></dl> |
| 1476 | |
| 1477 | <dl class="method"> |
| 1478 | <dt id="CI_DB_query_builder::dbprefix"> |
| 1479 | <code class="descname">dbprefix</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::dbprefix" title="Permalink to this definition">¶</a></dt> |
| 1480 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1481 | <col class="field-name" /> |
| 1482 | <col class="field-body" /> |
| 1483 | <tbody valign="top"> |
| 1484 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1485 | <li><strong>$table</strong> (<em>string</em>) – The table name to prefix</li> |
| 1486 | </ul> |
| 1487 | </td> |
| 1488 | </tr> |
| 1489 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The prefixed table name</p> |
| 1490 | </td> |
| 1491 | </tr> |
| 1492 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 1493 | </td> |
| 1494 | </tr> |
| 1495 | </tbody> |
| 1496 | </table> |
| 1497 | <p>Prepends a database prefix, if one exists in configuration.</p> |
| 1498 | </dd></dl> |
| 1499 | |
| 1500 | <dl class="method"> |
| 1501 | <dt id="CI_DB_query_builder::count_all_results"> |
| 1502 | <code class="descname">count_all_results</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::count_all_results" title="Permalink to this definition">¶</a></dt> |
| 1503 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1504 | <col class="field-name" /> |
| 1505 | <col class="field-body" /> |
| 1506 | <tbody valign="top"> |
| 1507 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1508 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 1509 | <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset values for SELECTs</li> |
| 1510 | </ul> |
| 1511 | </td> |
| 1512 | </tr> |
| 1513 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Number of rows in the query result</p> |
| 1514 | </td> |
| 1515 | </tr> |
| 1516 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">int</p> |
| 1517 | </td> |
| 1518 | </tr> |
| 1519 | </tbody> |
| 1520 | </table> |
| 1521 | <p>Generates a platform-specific query string that counts |
| 1522 | all records returned by an Query Builder query.</p> |
| 1523 | </dd></dl> |
| 1524 | |
| 1525 | <dl class="method"> |
| 1526 | <dt id="CI_DB_query_builder::get"> |
| 1527 | <code class="descname">get</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$limit = NULL</em><span class="optional">[</span>, <em>$offset = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get" title="Permalink to this definition">¶</a></dt> |
| 1528 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1529 | <col class="field-name" /> |
| 1530 | <col class="field-body" /> |
| 1531 | <tbody valign="top"> |
| 1532 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1533 | <li><strong>$table</strong> (<em>string</em>) – The table to query</li> |
| 1534 | <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li> |
| 1535 | <li><strong>$offset</strong> (<em>int</em>) – The OFFSET clause</li> |
| 1536 | </ul> |
| 1537 | </td> |
| 1538 | </tr> |
| 1539 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_result instance (method chaining)</p> |
| 1540 | </td> |
| 1541 | </tr> |
| 1542 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_result</p> |
| 1543 | </td> |
| 1544 | </tr> |
| 1545 | </tbody> |
| 1546 | </table> |
| 1547 | <p>Compiles and runs SELECT statement based on the already |
| 1548 | called Query Builder methods.</p> |
| 1549 | </dd></dl> |
| 1550 | |
| 1551 | <dl class="method"> |
| 1552 | <dt id="CI_DB_query_builder::get_where"> |
| 1553 | <code class="descname">get_where</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$where = NULL</em><span class="optional">[</span>, <em>$limit = NULL</em><span class="optional">[</span>, <em>$offset = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get_where" title="Permalink to this definition">¶</a></dt> |
| 1554 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1555 | <col class="field-name" /> |
| 1556 | <col class="field-body" /> |
| 1557 | <tbody valign="top"> |
| 1558 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1559 | <li><strong>$table</strong> (<em>mixed</em>) – The table(s) to fetch data from; string or array</li> |
| 1560 | <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li> |
| 1561 | <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li> |
| 1562 | <li><strong>$offset</strong> (<em>int</em>) – The OFFSET clause</li> |
| 1563 | </ul> |
| 1564 | </td> |
| 1565 | </tr> |
| 1566 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_result instance (method chaining)</p> |
| 1567 | </td> |
| 1568 | </tr> |
| 1569 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_result</p> |
| 1570 | </td> |
| 1571 | </tr> |
| 1572 | </tbody> |
| 1573 | </table> |
| 1574 | <p>Same as <code class="docutils literal"><span class="pre">get()</span></code>, but also allows the WHERE to be added directly.</p> |
| 1575 | </dd></dl> |
| 1576 | |
| 1577 | <dl class="method"> |
| 1578 | <dt id="CI_DB_query_builder::select"> |
| 1579 | <code class="descname">select</code><span class="sig-paren">(</span><span class="optional">[</span><em>$select = '*'</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::select" title="Permalink to this definition">¶</a></dt> |
| 1580 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1581 | <col class="field-name" /> |
| 1582 | <col class="field-body" /> |
| 1583 | <tbody valign="top"> |
| 1584 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1585 | <li><strong>$select</strong> (<em>string</em>) – The SELECT portion of a query</li> |
| 1586 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1587 | </ul> |
| 1588 | </td> |
| 1589 | </tr> |
| 1590 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1591 | </td> |
| 1592 | </tr> |
| 1593 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1594 | </td> |
| 1595 | </tr> |
| 1596 | </tbody> |
| 1597 | </table> |
| 1598 | <p>Adds a SELECT clause to a query.</p> |
| 1599 | </dd></dl> |
| 1600 | |
| 1601 | <dl class="method"> |
| 1602 | <dt id="CI_DB_query_builder::select_avg"> |
| 1603 | <code class="descname">select_avg</code><span class="sig-paren">(</span><span class="optional">[</span><em>$select = ''</em><span class="optional">[</span>, <em>$alias = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::select_avg" title="Permalink to this definition">¶</a></dt> |
| 1604 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1605 | <col class="field-name" /> |
| 1606 | <col class="field-body" /> |
| 1607 | <tbody valign="top"> |
| 1608 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1609 | <li><strong>$select</strong> (<em>string</em>) – Field to compute the average of</li> |
| 1610 | <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li> |
| 1611 | </ul> |
| 1612 | </td> |
| 1613 | </tr> |
| 1614 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1615 | </td> |
| 1616 | </tr> |
| 1617 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1618 | </td> |
| 1619 | </tr> |
| 1620 | </tbody> |
| 1621 | </table> |
| 1622 | <p>Adds a SELECT AVG(field) clause to a query.</p> |
| 1623 | </dd></dl> |
| 1624 | |
| 1625 | <dl class="method"> |
| 1626 | <dt id="CI_DB_query_builder::select_max"> |
| 1627 | <code class="descname">select_max</code><span class="sig-paren">(</span><span class="optional">[</span><em>$select = ''</em><span class="optional">[</span>, <em>$alias = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::select_max" title="Permalink to this definition">¶</a></dt> |
| 1628 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1629 | <col class="field-name" /> |
| 1630 | <col class="field-body" /> |
| 1631 | <tbody valign="top"> |
| 1632 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1633 | <li><strong>$select</strong> (<em>string</em>) – Field to compute the maximum of</li> |
| 1634 | <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li> |
| 1635 | </ul> |
| 1636 | </td> |
| 1637 | </tr> |
| 1638 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1639 | </td> |
| 1640 | </tr> |
| 1641 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1642 | </td> |
| 1643 | </tr> |
| 1644 | </tbody> |
| 1645 | </table> |
| 1646 | <p>Adds a SELECT MAX(field) clause to a query.</p> |
| 1647 | </dd></dl> |
| 1648 | |
| 1649 | <dl class="method"> |
| 1650 | <dt id="CI_DB_query_builder::select_min"> |
| 1651 | <code class="descname">select_min</code><span class="sig-paren">(</span><span class="optional">[</span><em>$select = ''</em><span class="optional">[</span>, <em>$alias = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::select_min" title="Permalink to this definition">¶</a></dt> |
| 1652 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1653 | <col class="field-name" /> |
| 1654 | <col class="field-body" /> |
| 1655 | <tbody valign="top"> |
| 1656 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1657 | <li><strong>$select</strong> (<em>string</em>) – Field to compute the minimum of</li> |
| 1658 | <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li> |
| 1659 | </ul> |
| 1660 | </td> |
| 1661 | </tr> |
| 1662 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1663 | </td> |
| 1664 | </tr> |
| 1665 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1666 | </td> |
| 1667 | </tr> |
| 1668 | </tbody> |
| 1669 | </table> |
| 1670 | <p>Adds a SELECT MIN(field) clause to a query.</p> |
| 1671 | </dd></dl> |
| 1672 | |
| 1673 | <dl class="method"> |
| 1674 | <dt id="CI_DB_query_builder::select_sum"> |
| 1675 | <code class="descname">select_sum</code><span class="sig-paren">(</span><span class="optional">[</span><em>$select = ''</em><span class="optional">[</span>, <em>$alias = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::select_sum" title="Permalink to this definition">¶</a></dt> |
| 1676 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1677 | <col class="field-name" /> |
| 1678 | <col class="field-body" /> |
| 1679 | <tbody valign="top"> |
| 1680 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1681 | <li><strong>$select</strong> (<em>string</em>) – Field to compute the sum of</li> |
| 1682 | <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li> |
| 1683 | </ul> |
| 1684 | </td> |
| 1685 | </tr> |
| 1686 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1687 | </td> |
| 1688 | </tr> |
| 1689 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1690 | </td> |
| 1691 | </tr> |
| 1692 | </tbody> |
| 1693 | </table> |
| 1694 | <p>Adds a SELECT SUM(field) clause to a query.</p> |
| 1695 | </dd></dl> |
| 1696 | |
| 1697 | <dl class="method"> |
| 1698 | <dt id="CI_DB_query_builder::distinct"> |
| 1699 | <code class="descname">distinct</code><span class="sig-paren">(</span><span class="optional">[</span><em>$val = TRUE</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::distinct" title="Permalink to this definition">¶</a></dt> |
| 1700 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1701 | <col class="field-name" /> |
| 1702 | <col class="field-body" /> |
| 1703 | <tbody valign="top"> |
| 1704 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1705 | <li><strong>$val</strong> (<em>bool</em>) – Desired value of the “distinct” flag</li> |
| 1706 | </ul> |
| 1707 | </td> |
| 1708 | </tr> |
| 1709 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1710 | </td> |
| 1711 | </tr> |
| 1712 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1713 | </td> |
| 1714 | </tr> |
| 1715 | </tbody> |
| 1716 | </table> |
| 1717 | <p>Sets a flag which tells the query builder to add |
| 1718 | a DISTINCT clause to the SELECT portion of the query.</p> |
| 1719 | </dd></dl> |
| 1720 | |
| 1721 | <dl class="method"> |
| 1722 | <dt id="CI_DB_query_builder::from"> |
| 1723 | <code class="descname">from</code><span class="sig-paren">(</span><em>$from</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::from" title="Permalink to this definition">¶</a></dt> |
| 1724 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1725 | <col class="field-name" /> |
| 1726 | <col class="field-body" /> |
| 1727 | <tbody valign="top"> |
| 1728 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1729 | <li><strong>$from</strong> (<em>mixed</em>) – Table name(s); string or array</li> |
| 1730 | </ul> |
| 1731 | </td> |
| 1732 | </tr> |
| 1733 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1734 | </td> |
| 1735 | </tr> |
| 1736 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1737 | </td> |
| 1738 | </tr> |
| 1739 | </tbody> |
| 1740 | </table> |
| 1741 | <p>Specifies the FROM clause of a query.</p> |
| 1742 | </dd></dl> |
| 1743 | |
| 1744 | <dl class="method"> |
| 1745 | <dt id="CI_DB_query_builder::join"> |
| 1746 | <code class="descname">join</code><span class="sig-paren">(</span><em>$table</em>, <em>$cond</em><span class="optional">[</span>, <em>$type = ''</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::join" title="Permalink to this definition">¶</a></dt> |
| 1747 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1748 | <col class="field-name" /> |
| 1749 | <col class="field-body" /> |
| 1750 | <tbody valign="top"> |
| 1751 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1752 | <li><strong>$table</strong> (<em>string</em>) – Table name to join</li> |
| 1753 | <li><strong>$cond</strong> (<em>string</em>) – The JOIN ON condition</li> |
| 1754 | <li><strong>$type</strong> (<em>string</em>) – The JOIN type</li> |
| 1755 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1756 | </ul> |
| 1757 | </td> |
| 1758 | </tr> |
| 1759 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 1760 | </td> |
| 1761 | </tr> |
| 1762 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 1763 | </td> |
| 1764 | </tr> |
| 1765 | </tbody> |
| 1766 | </table> |
| 1767 | <p>Adds a JOIN clause to a query.</p> |
| 1768 | </dd></dl> |
| 1769 | |
| 1770 | <dl class="method"> |
| 1771 | <dt id="CI_DB_query_builder::where"> |
| 1772 | <code class="descname">where</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::where" title="Permalink to this definition">¶</a></dt> |
| 1773 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1774 | <col class="field-name" /> |
| 1775 | <col class="field-body" /> |
| 1776 | <tbody valign="top"> |
| 1777 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1778 | <li><strong>$key</strong> (<em>mixed</em>) – Name of field to compare, or associative array</li> |
| 1779 | <li><strong>$value</strong> (<em>mixed</em>) – If a single key, compared to this value</li> |
| 1780 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1781 | </ul> |
| 1782 | </td> |
| 1783 | </tr> |
| 1784 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1785 | </td> |
| 1786 | </tr> |
| 1787 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1788 | </td> |
| 1789 | </tr> |
| 1790 | </tbody> |
| 1791 | </table> |
| 1792 | <p>Generates the WHERE portion of the query. |
| 1793 | Separates multiple calls with ‘AND’.</p> |
| 1794 | </dd></dl> |
| 1795 | |
| 1796 | <dl class="method"> |
| 1797 | <dt id="CI_DB_query_builder::or_where"> |
| 1798 | <code class="descname">or_where</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_where" title="Permalink to this definition">¶</a></dt> |
| 1799 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1800 | <col class="field-name" /> |
| 1801 | <col class="field-body" /> |
| 1802 | <tbody valign="top"> |
| 1803 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1804 | <li><strong>$key</strong> (<em>mixed</em>) – Name of field to compare, or associative array</li> |
| 1805 | <li><strong>$value</strong> (<em>mixed</em>) – If a single key, compared to this value</li> |
| 1806 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1807 | </ul> |
| 1808 | </td> |
| 1809 | </tr> |
| 1810 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1811 | </td> |
| 1812 | </tr> |
| 1813 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1814 | </td> |
| 1815 | </tr> |
| 1816 | </tbody> |
| 1817 | </table> |
| 1818 | <p>Generates the WHERE portion of the query. |
| 1819 | Separates multiple calls with ‘OR’.</p> |
| 1820 | </dd></dl> |
| 1821 | |
| 1822 | <dl class="method"> |
| 1823 | <dt id="CI_DB_query_builder::or_where_in"> |
| 1824 | <code class="descname">or_where_in</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">[</span>, <em>$values = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_where_in" title="Permalink to this definition">¶</a></dt> |
| 1825 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1826 | <col class="field-name" /> |
| 1827 | <col class="field-body" /> |
| 1828 | <tbody valign="top"> |
| 1829 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1830 | <li><strong>$key</strong> (<em>string</em>) – The field to search</li> |
| 1831 | <li><strong>$values</strong> (<em>array</em>) – The values searched on</li> |
| 1832 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1833 | </ul> |
| 1834 | </td> |
| 1835 | </tr> |
| 1836 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1837 | </td> |
| 1838 | </tr> |
| 1839 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1840 | </td> |
| 1841 | </tr> |
| 1842 | </tbody> |
| 1843 | </table> |
| 1844 | <p>Generates a WHERE field IN(‘item’, ‘item’) SQL query, |
| 1845 | joined with ‘OR’ if appropriate.</p> |
| 1846 | </dd></dl> |
| 1847 | |
| 1848 | <dl class="method"> |
| 1849 | <dt id="CI_DB_query_builder::or_where_not_in"> |
| 1850 | <code class="descname">or_where_not_in</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">[</span>, <em>$values = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_where_not_in" title="Permalink to this definition">¶</a></dt> |
| 1851 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1852 | <col class="field-name" /> |
| 1853 | <col class="field-body" /> |
| 1854 | <tbody valign="top"> |
| 1855 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1856 | <li><strong>$key</strong> (<em>string</em>) – The field to search</li> |
| 1857 | <li><strong>$values</strong> (<em>array</em>) – The values searched on</li> |
| 1858 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1859 | </ul> |
| 1860 | </td> |
| 1861 | </tr> |
| 1862 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1863 | </td> |
| 1864 | </tr> |
| 1865 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1866 | </td> |
| 1867 | </tr> |
| 1868 | </tbody> |
| 1869 | </table> |
| 1870 | <p>Generates a WHERE field NOT IN(‘item’, ‘item’) SQL query, |
| 1871 | joined with ‘OR’ if appropriate.</p> |
| 1872 | </dd></dl> |
| 1873 | |
| 1874 | <dl class="method"> |
| 1875 | <dt id="CI_DB_query_builder::where_in"> |
| 1876 | <code class="descname">where_in</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">[</span>, <em>$values = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::where_in" title="Permalink to this definition">¶</a></dt> |
| 1877 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1878 | <col class="field-name" /> |
| 1879 | <col class="field-body" /> |
| 1880 | <tbody valign="top"> |
| 1881 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1882 | <li><strong>$key</strong> (<em>string</em>) – Name of field to examine</li> |
| 1883 | <li><strong>$values</strong> (<em>array</em>) – Array of target values</li> |
| 1884 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1885 | </ul> |
| 1886 | </td> |
| 1887 | </tr> |
| 1888 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1889 | </td> |
| 1890 | </tr> |
| 1891 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1892 | </td> |
| 1893 | </tr> |
| 1894 | </tbody> |
| 1895 | </table> |
| 1896 | <p>Generates a WHERE field IN(‘item’, ‘item’) SQL query, |
| 1897 | joined with ‘AND’ if appropriate.</p> |
| 1898 | </dd></dl> |
| 1899 | |
| 1900 | <dl class="method"> |
| 1901 | <dt id="CI_DB_query_builder::where_not_in"> |
| 1902 | <code class="descname">where_not_in</code><span class="sig-paren">(</span><span class="optional">[</span><em>$key = NULL</em><span class="optional">[</span>, <em>$values = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::where_not_in" title="Permalink to this definition">¶</a></dt> |
| 1903 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1904 | <col class="field-name" /> |
| 1905 | <col class="field-body" /> |
| 1906 | <tbody valign="top"> |
| 1907 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 1908 | <li><strong>$key</strong> (<em>string</em>) – Name of field to examine</li> |
| 1909 | <li><strong>$values</strong> (<em>array</em>) – Array of target values</li> |
| 1910 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 1911 | </ul> |
| 1912 | </td> |
| 1913 | </tr> |
| 1914 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p> |
| 1915 | </td> |
| 1916 | </tr> |
| 1917 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p> |
| 1918 | </td> |
| 1919 | </tr> |
| 1920 | </tbody> |
| 1921 | </table> |
| 1922 | <p>Generates a WHERE field NOT IN(‘item’, ‘item’) SQL query, |
| 1923 | joined with ‘AND’ if appropriate.</p> |
| 1924 | </dd></dl> |
| 1925 | |
| 1926 | <dl class="method"> |
| 1927 | <dt id="CI_DB_query_builder::group_start"> |
| 1928 | <code class="descname">group_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::group_start" title="Permalink to this definition">¶</a></dt> |
| 1929 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1930 | <col class="field-name" /> |
| 1931 | <col class="field-body" /> |
| 1932 | <tbody valign="top"> |
| 1933 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1934 | </tr> |
| 1935 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1936 | </tr> |
| 1937 | </tbody> |
| 1938 | </table> |
| 1939 | <p>Starts a group expression, using ANDs for the conditions inside it.</p> |
| 1940 | </dd></dl> |
| 1941 | |
| 1942 | <dl class="method"> |
| 1943 | <dt id="CI_DB_query_builder::or_group_start"> |
| 1944 | <code class="descname">or_group_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_group_start" title="Permalink to this definition">¶</a></dt> |
| 1945 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1946 | <col class="field-name" /> |
| 1947 | <col class="field-body" /> |
| 1948 | <tbody valign="top"> |
| 1949 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1950 | </tr> |
| 1951 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1952 | </tr> |
| 1953 | </tbody> |
| 1954 | </table> |
| 1955 | <p>Starts a group expression, using ORs for the conditions inside it.</p> |
| 1956 | </dd></dl> |
| 1957 | |
| 1958 | <dl class="method"> |
| 1959 | <dt id="CI_DB_query_builder::not_group_start"> |
| 1960 | <code class="descname">not_group_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::not_group_start" title="Permalink to this definition">¶</a></dt> |
| 1961 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1962 | <col class="field-name" /> |
| 1963 | <col class="field-body" /> |
| 1964 | <tbody valign="top"> |
| 1965 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1966 | </tr> |
| 1967 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1968 | </tr> |
| 1969 | </tbody> |
| 1970 | </table> |
| 1971 | <p>Starts a group expression, using AND NOTs for the conditions inside it.</p> |
| 1972 | </dd></dl> |
| 1973 | |
| 1974 | <dl class="method"> |
| 1975 | <dt id="CI_DB_query_builder::or_not_group_start"> |
| 1976 | <code class="descname">or_not_group_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_not_group_start" title="Permalink to this definition">¶</a></dt> |
| 1977 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1978 | <col class="field-name" /> |
| 1979 | <col class="field-body" /> |
| 1980 | <tbody valign="top"> |
| 1981 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td> |
| 1982 | </tr> |
| 1983 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td> |
| 1984 | </tr> |
| 1985 | </tbody> |
| 1986 | </table> |
| 1987 | <p>Starts a group expression, using OR NOTs for the conditions inside it.</p> |
| 1988 | </dd></dl> |
| 1989 | |
| 1990 | <dl class="method"> |
| 1991 | <dt id="CI_DB_query_builder::group_end"> |
| 1992 | <code class="descname">group_end</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::group_end" title="Permalink to this definition">¶</a></dt> |
| 1993 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 1994 | <col class="field-name" /> |
| 1995 | <col class="field-body" /> |
| 1996 | <tbody valign="top"> |
| 1997 | <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">DB_query_builder instance</td> |
| 1998 | </tr> |
| 1999 | <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">object</td> |
| 2000 | </tr> |
| 2001 | </tbody> |
| 2002 | </table> |
| 2003 | <p>Ends a group expression.</p> |
| 2004 | </dd></dl> |
| 2005 | |
| 2006 | <dl class="method"> |
| 2007 | <dt id="CI_DB_query_builder::like"> |
| 2008 | <code class="descname">like</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$match = ''</em><span class="optional">[</span>, <em>$side = 'both'</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::like" title="Permalink to this definition">¶</a></dt> |
| 2009 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2010 | <col class="field-name" /> |
| 2011 | <col class="field-body" /> |
| 2012 | <tbody valign="top"> |
| 2013 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2014 | <li><strong>$field</strong> (<em>string</em>) – Field name</li> |
| 2015 | <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li> |
| 2016 | <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li> |
| 2017 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2018 | </ul> |
| 2019 | </td> |
| 2020 | </tr> |
| 2021 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2022 | </td> |
| 2023 | </tr> |
| 2024 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2025 | </td> |
| 2026 | </tr> |
| 2027 | </tbody> |
| 2028 | </table> |
| 2029 | <p>Adds a LIKE clause to a query, separating multiple calls with AND.</p> |
| 2030 | </dd></dl> |
| 2031 | |
| 2032 | <dl class="method"> |
| 2033 | <dt id="CI_DB_query_builder::or_like"> |
| 2034 | <code class="descname">or_like</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$match = ''</em><span class="optional">[</span>, <em>$side = 'both'</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_like" title="Permalink to this definition">¶</a></dt> |
| 2035 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2036 | <col class="field-name" /> |
| 2037 | <col class="field-body" /> |
| 2038 | <tbody valign="top"> |
| 2039 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2040 | <li><strong>$field</strong> (<em>string</em>) – Field name</li> |
| 2041 | <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li> |
| 2042 | <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li> |
| 2043 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2044 | </ul> |
| 2045 | </td> |
| 2046 | </tr> |
| 2047 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2048 | </td> |
| 2049 | </tr> |
| 2050 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2051 | </td> |
| 2052 | </tr> |
| 2053 | </tbody> |
| 2054 | </table> |
| 2055 | <p>Adds a LIKE clause to a query, separating multiple class with OR.</p> |
| 2056 | </dd></dl> |
| 2057 | |
| 2058 | <dl class="method"> |
| 2059 | <dt id="CI_DB_query_builder::not_like"> |
| 2060 | <code class="descname">not_like</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$match = ''</em><span class="optional">[</span>, <em>$side = 'both'</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::not_like" title="Permalink to this definition">¶</a></dt> |
| 2061 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2062 | <col class="field-name" /> |
| 2063 | <col class="field-body" /> |
| 2064 | <tbody valign="top"> |
| 2065 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2066 | <li><strong>$field</strong> (<em>string</em>) – Field name</li> |
| 2067 | <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li> |
| 2068 | <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li> |
| 2069 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2070 | </ul> |
| 2071 | </td> |
| 2072 | </tr> |
| 2073 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2074 | </td> |
| 2075 | </tr> |
| 2076 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2077 | </td> |
| 2078 | </tr> |
| 2079 | </tbody> |
| 2080 | </table> |
| 2081 | <p>Adds a NOT LIKE clause to a query, separating multiple calls with AND.</p> |
| 2082 | </dd></dl> |
| 2083 | |
| 2084 | <dl class="method"> |
| 2085 | <dt id="CI_DB_query_builder::or_not_like"> |
| 2086 | <code class="descname">or_not_like</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$match = ''</em><span class="optional">[</span>, <em>$side = 'both'</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_not_like" title="Permalink to this definition">¶</a></dt> |
| 2087 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2088 | <col class="field-name" /> |
| 2089 | <col class="field-body" /> |
| 2090 | <tbody valign="top"> |
| 2091 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2092 | <li><strong>$field</strong> (<em>string</em>) – Field name</li> |
| 2093 | <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li> |
| 2094 | <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li> |
| 2095 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2096 | </ul> |
| 2097 | </td> |
| 2098 | </tr> |
| 2099 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2100 | </td> |
| 2101 | </tr> |
| 2102 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2103 | </td> |
| 2104 | </tr> |
| 2105 | </tbody> |
| 2106 | </table> |
| 2107 | <p>Adds a NOT LIKE clause to a query, separating multiple calls with OR.</p> |
| 2108 | </dd></dl> |
| 2109 | |
| 2110 | <dl class="method"> |
| 2111 | <dt id="CI_DB_query_builder::having"> |
| 2112 | <code class="descname">having</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::having" title="Permalink to this definition">¶</a></dt> |
| 2113 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2114 | <col class="field-name" /> |
| 2115 | <col class="field-body" /> |
| 2116 | <tbody valign="top"> |
| 2117 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2118 | <li><strong>$key</strong> (<em>mixed</em>) – Identifier (string) or associative array of field/value pairs</li> |
| 2119 | <li><strong>$value</strong> (<em>string</em>) – Value sought if $key is an identifier</li> |
| 2120 | <li><strong>$escape</strong> (<em>string</em>) – Whether to escape values and identifiers</li> |
| 2121 | </ul> |
| 2122 | </td> |
| 2123 | </tr> |
| 2124 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2125 | </td> |
| 2126 | </tr> |
| 2127 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2128 | </td> |
| 2129 | </tr> |
| 2130 | </tbody> |
| 2131 | </table> |
| 2132 | <p>Adds a HAVING clause to a query, separating multiple calls with AND.</p> |
| 2133 | </dd></dl> |
| 2134 | |
| 2135 | <dl class="method"> |
| 2136 | <dt id="CI_DB_query_builder::or_having"> |
| 2137 | <code class="descname">or_having</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::or_having" title="Permalink to this definition">¶</a></dt> |
| 2138 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2139 | <col class="field-name" /> |
| 2140 | <col class="field-body" /> |
| 2141 | <tbody valign="top"> |
| 2142 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2143 | <li><strong>$key</strong> (<em>mixed</em>) – Identifier (string) or associative array of field/value pairs</li> |
| 2144 | <li><strong>$value</strong> (<em>string</em>) – Value sought if $key is an identifier</li> |
| 2145 | <li><strong>$escape</strong> (<em>string</em>) – Whether to escape values and identifiers</li> |
| 2146 | </ul> |
| 2147 | </td> |
| 2148 | </tr> |
| 2149 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2150 | </td> |
| 2151 | </tr> |
| 2152 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2153 | </td> |
| 2154 | </tr> |
| 2155 | </tbody> |
| 2156 | </table> |
| 2157 | <p>Adds a HAVING clause to a query, separating multiple calls with OR.</p> |
| 2158 | </dd></dl> |
| 2159 | |
| 2160 | <dl class="method"> |
| 2161 | <dt id="CI_DB_query_builder::group_by"> |
| 2162 | <code class="descname">group_by</code><span class="sig-paren">(</span><em>$by</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::group_by" title="Permalink to this definition">¶</a></dt> |
| 2163 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2164 | <col class="field-name" /> |
| 2165 | <col class="field-body" /> |
| 2166 | <tbody valign="top"> |
| 2167 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2168 | <li><strong>$by</strong> (<em>mixed</em>) – Field(s) to group by; string or array</li> |
| 2169 | </ul> |
| 2170 | </td> |
| 2171 | </tr> |
| 2172 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2173 | </td> |
| 2174 | </tr> |
| 2175 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2176 | </td> |
| 2177 | </tr> |
| 2178 | </tbody> |
| 2179 | </table> |
| 2180 | <p>Adds a GROUP BY clause to a query.</p> |
| 2181 | </dd></dl> |
| 2182 | |
| 2183 | <dl class="method"> |
| 2184 | <dt id="CI_DB_query_builder::order_by"> |
| 2185 | <code class="descname">order_by</code><span class="sig-paren">(</span><em>$orderby</em><span class="optional">[</span>, <em>$direction = ''</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::order_by" title="Permalink to this definition">¶</a></dt> |
| 2186 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2187 | <col class="field-name" /> |
| 2188 | <col class="field-body" /> |
| 2189 | <tbody valign="top"> |
| 2190 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2191 | <li><strong>$orderby</strong> (<em>string</em>) – Field to order by</li> |
| 2192 | <li><strong>$direction</strong> (<em>string</em>) – The order requested - ASC, DESC or random</li> |
| 2193 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2194 | </ul> |
| 2195 | </td> |
| 2196 | </tr> |
| 2197 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2198 | </td> |
| 2199 | </tr> |
| 2200 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2201 | </td> |
| 2202 | </tr> |
| 2203 | </tbody> |
| 2204 | </table> |
| 2205 | <p>Adds an ORDER BY clause to a query.</p> |
| 2206 | </dd></dl> |
| 2207 | |
| 2208 | <dl class="method"> |
| 2209 | <dt id="CI_DB_query_builder::limit"> |
| 2210 | <code class="descname">limit</code><span class="sig-paren">(</span><em>$value</em><span class="optional">[</span>, <em>$offset = 0</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::limit" title="Permalink to this definition">¶</a></dt> |
| 2211 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2212 | <col class="field-name" /> |
| 2213 | <col class="field-body" /> |
| 2214 | <tbody valign="top"> |
| 2215 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2216 | <li><strong>$value</strong> (<em>int</em>) – Number of rows to limit the results to</li> |
| 2217 | <li><strong>$offset</strong> (<em>int</em>) – Number of rows to skip</li> |
| 2218 | </ul> |
| 2219 | </td> |
| 2220 | </tr> |
| 2221 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2222 | </td> |
| 2223 | </tr> |
| 2224 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2225 | </td> |
| 2226 | </tr> |
| 2227 | </tbody> |
| 2228 | </table> |
| 2229 | <p>Adds LIMIT and OFFSET clauses to a query.</p> |
| 2230 | </dd></dl> |
| 2231 | |
| 2232 | <dl class="method"> |
| 2233 | <dt id="CI_DB_query_builder::offset"> |
| 2234 | <code class="descname">offset</code><span class="sig-paren">(</span><em>$offset</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::offset" title="Permalink to this definition">¶</a></dt> |
| 2235 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2236 | <col class="field-name" /> |
| 2237 | <col class="field-body" /> |
| 2238 | <tbody valign="top"> |
| 2239 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2240 | <li><strong>$offset</strong> (<em>int</em>) – Number of rows to skip</li> |
| 2241 | </ul> |
| 2242 | </td> |
| 2243 | </tr> |
| 2244 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2245 | </td> |
| 2246 | </tr> |
| 2247 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2248 | </td> |
| 2249 | </tr> |
| 2250 | </tbody> |
| 2251 | </table> |
| 2252 | <p>Adds an OFFSET clause to a query.</p> |
| 2253 | </dd></dl> |
| 2254 | |
| 2255 | <dl class="method"> |
| 2256 | <dt id="CI_DB_query_builder::set"> |
| 2257 | <code class="descname">set</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = ''</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::set" title="Permalink to this definition">¶</a></dt> |
| 2258 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2259 | <col class="field-name" /> |
| 2260 | <col class="field-body" /> |
| 2261 | <tbody valign="top"> |
| 2262 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2263 | <li><strong>$key</strong> (<em>mixed</em>) – Field name, or an array of field/value pairs</li> |
| 2264 | <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li> |
| 2265 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2266 | </ul> |
| 2267 | </td> |
| 2268 | </tr> |
| 2269 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2270 | </td> |
| 2271 | </tr> |
| 2272 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2273 | </td> |
| 2274 | </tr> |
| 2275 | </tbody> |
| 2276 | </table> |
| 2277 | <p>Adds field/value pairs to be passed later to <code class="docutils literal"><span class="pre">insert()</span></code>, |
| 2278 | <code class="docutils literal"><span class="pre">update()</span></code> or <code class="docutils literal"><span class="pre">replace()</span></code>.</p> |
| 2279 | </dd></dl> |
| 2280 | |
| 2281 | <dl class="method"> |
| 2282 | <dt id="CI_DB_query_builder::insert"> |
| 2283 | <code class="descname">insert</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$set = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::insert" title="Permalink to this definition">¶</a></dt> |
| 2284 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2285 | <col class="field-name" /> |
| 2286 | <col class="field-body" /> |
| 2287 | <tbody valign="top"> |
| 2288 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2289 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2290 | <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li> |
| 2291 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2292 | </ul> |
| 2293 | </td> |
| 2294 | </tr> |
| 2295 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p> |
| 2296 | </td> |
| 2297 | </tr> |
| 2298 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| 2299 | </td> |
| 2300 | </tr> |
| 2301 | </tbody> |
| 2302 | </table> |
| 2303 | <p>Compiles and executes an INSERT statement.</p> |
| 2304 | </dd></dl> |
| 2305 | |
| 2306 | <dl class="method"> |
| 2307 | <dt id="CI_DB_query_builder::insert_batch"> |
| 2308 | <code class="descname">insert_batch</code><span class="sig-paren">(</span><em>$table</em><span class="optional">[</span>, <em>$set = NULL</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">[</span>, <em>$batch_size = 100</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::insert_batch" title="Permalink to this definition">¶</a></dt> |
| 2309 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2310 | <col class="field-name" /> |
| 2311 | <col class="field-body" /> |
| 2312 | <tbody valign="top"> |
| 2313 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2314 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2315 | <li><strong>$set</strong> (<em>array</em>) – Data to insert</li> |
| 2316 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2317 | <li><strong>$batch_size</strong> (<em>int</em>) – Count of rows to insert at once</li> |
| 2318 | </ul> |
| 2319 | </td> |
| 2320 | </tr> |
| 2321 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Number of rows inserted or FALSE on failure</p> |
| 2322 | </td> |
| 2323 | </tr> |
| 2324 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p> |
| 2325 | </td> |
| 2326 | </tr> |
| 2327 | </tbody> |
| 2328 | </table> |
| 2329 | <p>Compiles and executes batch <code class="docutils literal"><span class="pre">INSERT</span></code> statements.</p> |
| 2330 | <div class="admonition note"> |
| 2331 | <p class="first admonition-title">Note</p> |
| 2332 | <p class="last">When more than <code class="docutils literal"><span class="pre">$batch_size</span></code> rows are provided, multiple |
| 2333 | <code class="docutils literal"><span class="pre">INSERT</span></code> queries will be executed, each trying to insert |
| 2334 | up to <code class="docutils literal"><span class="pre">$batch_size</span></code> rows.</p> |
| 2335 | </div> |
| 2336 | </dd></dl> |
| 2337 | |
| 2338 | <dl class="method"> |
| 2339 | <dt id="CI_DB_query_builder::set_insert_batch"> |
| 2340 | <code class="descname">set_insert_batch</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = ''</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::set_insert_batch" title="Permalink to this definition">¶</a></dt> |
| 2341 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2342 | <col class="field-name" /> |
| 2343 | <col class="field-body" /> |
| 2344 | <tbody valign="top"> |
| 2345 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2346 | <li><strong>$key</strong> (<em>mixed</em>) – Field name or an array of field/value pairs</li> |
| 2347 | <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li> |
| 2348 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2349 | </ul> |
| 2350 | </td> |
| 2351 | </tr> |
| 2352 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2353 | </td> |
| 2354 | </tr> |
| 2355 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2356 | </td> |
| 2357 | </tr> |
| 2358 | </tbody> |
| 2359 | </table> |
| 2360 | <p>Adds field/value pairs to be inserted in a table later via <code class="docutils literal"><span class="pre">insert_batch()</span></code>.</p> |
| 2361 | </dd></dl> |
| 2362 | |
| 2363 | <dl class="method"> |
| 2364 | <dt id="CI_DB_query_builder::update"> |
| 2365 | <code class="descname">update</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$set = NULL</em><span class="optional">[</span>, <em>$where = NULL</em><span class="optional">[</span>, <em>$limit = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::update" title="Permalink to this definition">¶</a></dt> |
| 2366 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2367 | <col class="field-name" /> |
| 2368 | <col class="field-body" /> |
| 2369 | <tbody valign="top"> |
| 2370 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2371 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2372 | <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li> |
| 2373 | <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li> |
| 2374 | <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li> |
| 2375 | </ul> |
| 2376 | </td> |
| 2377 | </tr> |
| 2378 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p> |
| 2379 | </td> |
| 2380 | </tr> |
| 2381 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| 2382 | </td> |
| 2383 | </tr> |
| 2384 | </tbody> |
| 2385 | </table> |
| 2386 | <p>Compiles and executes an UPDATE statement.</p> |
| 2387 | </dd></dl> |
| 2388 | |
| 2389 | <dl class="method"> |
| 2390 | <dt id="CI_DB_query_builder::update_batch"> |
| 2391 | <code class="descname">update_batch</code><span class="sig-paren">(</span><em>$table</em><span class="optional">[</span>, <em>$set = NULL</em><span class="optional">[</span>, <em>$value = NULL</em><span class="optional">[</span>, <em>$batch_size = 100</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::update_batch" title="Permalink to this definition">¶</a></dt> |
| 2392 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2393 | <col class="field-name" /> |
| 2394 | <col class="field-body" /> |
| 2395 | <tbody valign="top"> |
| 2396 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2397 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2398 | <li><strong>$set</strong> (<em>array</em>) – Field name, or an associative array of field/value pairs</li> |
| 2399 | <li><strong>$value</strong> (<em>string</em>) – Field value, if $set is a single field</li> |
| 2400 | <li><strong>$batch_size</strong> (<em>int</em>) – Count of conditions to group in a single query</li> |
| 2401 | </ul> |
| 2402 | </td> |
| 2403 | </tr> |
| 2404 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Number of rows updated or FALSE on failure</p> |
| 2405 | </td> |
| 2406 | </tr> |
| 2407 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p> |
| 2408 | </td> |
| 2409 | </tr> |
| 2410 | </tbody> |
| 2411 | </table> |
| 2412 | <p>Compiles and executes batch <code class="docutils literal"><span class="pre">UPDATE</span></code> statements.</p> |
| 2413 | <div class="admonition note"> |
| 2414 | <p class="first admonition-title">Note</p> |
| 2415 | <p class="last">When more than <code class="docutils literal"><span class="pre">$batch_size</span></code> field/value pairs are provided, |
| 2416 | multiple queries will be executed, each handling up to |
| 2417 | <code class="docutils literal"><span class="pre">$batch_size</span></code> field/value pairs.</p> |
| 2418 | </div> |
| 2419 | </dd></dl> |
| 2420 | |
| 2421 | <dl class="method"> |
| 2422 | <dt id="CI_DB_query_builder::set_update_batch"> |
| 2423 | <code class="descname">set_update_batch</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$value = ''</em><span class="optional">[</span>, <em>$escape = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::set_update_batch" title="Permalink to this definition">¶</a></dt> |
| 2424 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2425 | <col class="field-name" /> |
| 2426 | <col class="field-body" /> |
| 2427 | <tbody valign="top"> |
| 2428 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2429 | <li><strong>$key</strong> (<em>mixed</em>) – Field name or an array of field/value pairs</li> |
| 2430 | <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li> |
| 2431 | <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li> |
| 2432 | </ul> |
| 2433 | </td> |
| 2434 | </tr> |
| 2435 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining)</p> |
| 2436 | </td> |
| 2437 | </tr> |
| 2438 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_query_builder</p> |
| 2439 | </td> |
| 2440 | </tr> |
| 2441 | </tbody> |
| 2442 | </table> |
| 2443 | <p>Adds field/value pairs to be updated in a table later via <code class="docutils literal"><span class="pre">update_batch()</span></code>.</p> |
| 2444 | </dd></dl> |
| 2445 | |
| 2446 | <dl class="method"> |
| 2447 | <dt id="CI_DB_query_builder::replace"> |
| 2448 | <code class="descname">replace</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$set = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::replace" title="Permalink to this definition">¶</a></dt> |
| 2449 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2450 | <col class="field-name" /> |
| 2451 | <col class="field-body" /> |
| 2452 | <tbody valign="top"> |
| 2453 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2454 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2455 | <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li> |
| 2456 | </ul> |
| 2457 | </td> |
| 2458 | </tr> |
| 2459 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p> |
| 2460 | </td> |
| 2461 | </tr> |
| 2462 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| 2463 | </td> |
| 2464 | </tr> |
| 2465 | </tbody> |
| 2466 | </table> |
| 2467 | <p>Compiles and executes a REPLACE statement.</p> |
| 2468 | </dd></dl> |
| 2469 | |
| 2470 | <dl class="method"> |
| 2471 | <dt id="CI_DB_query_builder::delete"> |
| 2472 | <code class="descname">delete</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$where = ''</em><span class="optional">[</span>, <em>$limit = NULL</em><span class="optional">[</span>, <em>$reset_data = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::delete" title="Permalink to this definition">¶</a></dt> |
| 2473 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2474 | <col class="field-name" /> |
| 2475 | <col class="field-body" /> |
| 2476 | <tbody valign="top"> |
| 2477 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2478 | <li><strong>$table</strong> (<em>mixed</em>) – The table(s) to delete from; string or array</li> |
| 2479 | <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li> |
| 2480 | <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li> |
| 2481 | <li><strong>$reset_data</strong> (<em>bool</em>) – TRUE to reset the query “write” clause</li> |
| 2482 | </ul> |
| 2483 | </td> |
| 2484 | </tr> |
| 2485 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_query_builder instance (method chaining) or FALSE on failure</p> |
| 2486 | </td> |
| 2487 | </tr> |
| 2488 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p> |
| 2489 | </td> |
| 2490 | </tr> |
| 2491 | </tbody> |
| 2492 | </table> |
| 2493 | <p>Compiles and executes a DELETE query.</p> |
| 2494 | </dd></dl> |
| 2495 | |
| 2496 | <dl class="method"> |
| 2497 | <dt id="CI_DB_query_builder::truncate"> |
| 2498 | <code class="descname">truncate</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::truncate" title="Permalink to this definition">¶</a></dt> |
| 2499 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2500 | <col class="field-name" /> |
| 2501 | <col class="field-body" /> |
| 2502 | <tbody valign="top"> |
| 2503 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2504 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2505 | </ul> |
| 2506 | </td> |
| 2507 | </tr> |
| 2508 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p> |
| 2509 | </td> |
| 2510 | </tr> |
| 2511 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| 2512 | </td> |
| 2513 | </tr> |
| 2514 | </tbody> |
| 2515 | </table> |
| 2516 | <p>Executes a TRUNCATE statement on a table.</p> |
| 2517 | <div class="admonition note"> |
| 2518 | <p class="first admonition-title">Note</p> |
| 2519 | <p class="last">If the database platform in use doesn’t support TRUNCATE, |
| 2520 | a DELETE statement will be used instead.</p> |
| 2521 | </div> |
| 2522 | </dd></dl> |
| 2523 | |
| 2524 | <dl class="method"> |
| 2525 | <dt id="CI_DB_query_builder::empty_table"> |
| 2526 | <code class="descname">empty_table</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::empty_table" title="Permalink to this definition">¶</a></dt> |
| 2527 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2528 | <col class="field-name" /> |
| 2529 | <col class="field-body" /> |
| 2530 | <tbody valign="top"> |
| 2531 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2532 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2533 | </ul> |
| 2534 | </td> |
| 2535 | </tr> |
| 2536 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p> |
| 2537 | </td> |
| 2538 | </tr> |
| 2539 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p> |
| 2540 | </td> |
| 2541 | </tr> |
| 2542 | </tbody> |
| 2543 | </table> |
| 2544 | <p>Deletes all records from a table via a DELETE statement.</p> |
| 2545 | </dd></dl> |
| 2546 | |
| 2547 | <dl class="method"> |
| 2548 | <dt id="CI_DB_query_builder::get_compiled_select"> |
| 2549 | <code class="descname">get_compiled_select</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get_compiled_select" title="Permalink to this definition">¶</a></dt> |
| 2550 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2551 | <col class="field-name" /> |
| 2552 | <col class="field-body" /> |
| 2553 | <tbody valign="top"> |
| 2554 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2555 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2556 | <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li> |
| 2557 | </ul> |
| 2558 | </td> |
| 2559 | </tr> |
| 2560 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compiled SQL statement as a string</p> |
| 2561 | </td> |
| 2562 | </tr> |
| 2563 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 2564 | </td> |
| 2565 | </tr> |
| 2566 | </tbody> |
| 2567 | </table> |
| 2568 | <p>Compiles a SELECT statement and returns it as a string.</p> |
| 2569 | </dd></dl> |
| 2570 | |
| 2571 | <dl class="method"> |
| 2572 | <dt id="CI_DB_query_builder::get_compiled_insert"> |
| 2573 | <code class="descname">get_compiled_insert</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get_compiled_insert" title="Permalink to this definition">¶</a></dt> |
| 2574 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2575 | <col class="field-name" /> |
| 2576 | <col class="field-body" /> |
| 2577 | <tbody valign="top"> |
| 2578 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2579 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2580 | <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li> |
| 2581 | </ul> |
| 2582 | </td> |
| 2583 | </tr> |
| 2584 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compiled SQL statement as a string</p> |
| 2585 | </td> |
| 2586 | </tr> |
| 2587 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 2588 | </td> |
| 2589 | </tr> |
| 2590 | </tbody> |
| 2591 | </table> |
| 2592 | <p>Compiles an INSERT statement and returns it as a string.</p> |
| 2593 | </dd></dl> |
| 2594 | |
| 2595 | <dl class="method"> |
| 2596 | <dt id="CI_DB_query_builder::get_compiled_update"> |
| 2597 | <code class="descname">get_compiled_update</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get_compiled_update" title="Permalink to this definition">¶</a></dt> |
| 2598 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2599 | <col class="field-name" /> |
| 2600 | <col class="field-body" /> |
| 2601 | <tbody valign="top"> |
| 2602 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2603 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2604 | <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li> |
| 2605 | </ul> |
| 2606 | </td> |
| 2607 | </tr> |
| 2608 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compiled SQL statement as a string</p> |
| 2609 | </td> |
| 2610 | </tr> |
| 2611 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 2612 | </td> |
| 2613 | </tr> |
| 2614 | </tbody> |
| 2615 | </table> |
| 2616 | <p>Compiles an UPDATE statement and returns it as a string.</p> |
| 2617 | </dd></dl> |
| 2618 | |
| 2619 | <dl class="method"> |
| 2620 | <dt id="CI_DB_query_builder::get_compiled_delete"> |
| 2621 | <code class="descname">get_compiled_delete</code><span class="sig-paren">(</span><span class="optional">[</span><em>$table = ''</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_query_builder::get_compiled_delete" title="Permalink to this definition">¶</a></dt> |
| 2622 | <dd><table class="docutils field-list" frame="void" rules="none"> |
| 2623 | <col class="field-name" /> |
| 2624 | <col class="field-body" /> |
| 2625 | <tbody valign="top"> |
| 2626 | <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> |
| 2627 | <li><strong>$table</strong> (<em>string</em>) – Table name</li> |
| 2628 | <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li> |
| 2629 | </ul> |
| 2630 | </td> |
| 2631 | </tr> |
| 2632 | <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compiled SQL statement as a string</p> |
| 2633 | </td> |
| 2634 | </tr> |
| 2635 | <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p> |
| 2636 | </td> |
| 2637 | </tr> |
| 2638 | </tbody> |
| 2639 | </table> |
| 2640 | <p>Compiles a DELETE statement and returns it as a string.</p> |
| 2641 | </dd></dl> |
| 2642 | |
| 2643 | </dd></dl> |
| 2644 | |
| 2645 | </div> |
| 2646 | </div> |
| 2647 | |
| 2648 | |
| 2649 | </div> |
| 2650 | <footer> |
| 2651 | |
| 2652 | <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| 2653 | |
| 2654 | <a href="transactions.html" class="btn btn-neutral float-right" title="Transactions">Next <span class="fa fa-arrow-circle-right"></span></a> |
| 2655 | |
| 2656 | |
| 2657 | <a href="helpers.html" class="btn btn-neutral" title="Query Helper Methods"><span class="fa fa-arrow-circle-left"></span> Previous</a> |
| 2658 | |
| 2659 | </div> |
| 2660 | |
| 2661 | |
| 2662 | <hr/> |
| 2663 | |
| 2664 | <div role="contentinfo"> |
| 2665 | <p> |
| 2666 | © Copyright 2014 - 2019, British Columbia Institute of Technology. |
| 2667 | Last updated on Jan 16, 2019. |
| 2668 | </p> |
| 2669 | </div> |
| 2670 | |
| 2671 | 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>. |
| 2672 | |
| 2673 | </footer> |
| 2674 | </div> |
| 2675 | </div> |
| 2676 | |
| 2677 | </section> |
| 2678 | |
| 2679 | </div> |
| 2680 | |
| 2681 | |
| 2682 | |
| 2683 | |
| 2684 | |
| 2685 | <script type="text/javascript"> |
| 2686 | var DOCUMENTATION_OPTIONS = { |
| 2687 | URL_ROOT:'../', |
| 2688 | VERSION:'3.1.10', |
| 2689 | COLLAPSE_INDEX:false, |
| 2690 | FILE_SUFFIX:'.html', |
| 2691 | HAS_SOURCE: false |
| 2692 | }; |
| 2693 | </script> |
| 2694 | <script type="text/javascript" src="../_static/jquery.js"></script> |
| 2695 | <script type="text/javascript" src="../_static/underscore.js"></script> |
| 2696 | <script type="text/javascript" src="../_static/doctools.js"></script> |
| 2697 | |
| 2698 | |
| 2699 | |
| 2700 | |
| 2701 | |
| 2702 | <script type="text/javascript" src="../_static/js/theme.js"></script> |
| 2703 | |
| 2704 | |
| 2705 | |
| 2706 | |
| 2707 | <script type="text/javascript"> |
| 2708 | jQuery(function () { |
| 2709 | SphinxRtdTheme.StickyNav.enable(); |
| 2710 | }); |
| 2711 | </script> |
| 2712 | |
| 2713 | |
| 2714 | </body> |
| 2715 | </html> |