forge.html 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Database Forge Class &mdash; CodeIgniter 3.1.11 documentation</title>
  8. <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
  9. <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'>
  10. <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
  11. <link rel="index" title="Index"
  12. href="../genindex.html"/>
  13. <link rel="search" title="Search" href="../search.html"/>
  14. <link rel="top" title="CodeIgniter 3.1.11 documentation" href="../index.html"/>
  15. <link rel="up" title="Database Reference" href="index.html"/>
  16. <link rel="next" title="Database Utility Class" href="utilities.html"/>
  17. <link rel="prev" title="Database Caching Class" href="caching.html"/>
  18. <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
  19. </head>
  20. <body class="wy-body-for-nav" role="document">
  21. <div id="nav">
  22. <div id="nav_inner">
  23. <div id="pulldown-menu" class="ciNav">
  24. <ul>
  25. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  26. </ul>
  27. <ul>
  28. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  29. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  30. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  31. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  32. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  33. </ul>
  34. </li>
  35. </ul>
  36. <ul>
  37. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  38. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  39. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  40. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  41. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  42. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  43. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  44. </ul>
  45. </li>
  46. </ul>
  47. <ul>
  48. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  49. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  50. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  51. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  52. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  53. </ul>
  54. </li>
  55. </ul>
  56. <ul>
  57. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  58. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  59. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  60. </ul>
  61. </li>
  62. </ul>
  63. <ul>
  64. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  65. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  66. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  67. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  68. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  69. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  70. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  71. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  72. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  73. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  74. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  75. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  76. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  77. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  78. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  79. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  80. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  81. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  82. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  83. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  84. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  85. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  86. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  87. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  88. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  89. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  90. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  91. </ul>
  92. </li>
  93. </ul>
  94. <ul>
  95. <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
  96. <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
  97. <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
  98. <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
  99. <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
  100. <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
  101. <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
  102. <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
  103. <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
  104. <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
  105. <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
  106. <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
  107. <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
  108. <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
  109. <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
  110. <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
  111. <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
  112. <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
  113. <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
  114. <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
  115. <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
  116. <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
  117. <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
  118. <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
  119. <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
  120. <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
  121. <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
  122. <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
  123. <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
  124. <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  125. <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
  126. </ul>
  127. </li>
  128. </ul>
  129. <ul class="current">
  130. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
  131. <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
  132. <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
  133. <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
  134. <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
  135. <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li>
  136. <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
  137. <li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li>
  138. <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
  139. <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
  140. <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
  141. <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
  142. <li class="toctree-l2 current"><a class="current reference internal" href="#">Database Manipulation with Database Forge</a></li>
  143. <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
  144. <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
  145. </ul>
  146. </li>
  147. </ul>
  148. <ul>
  149. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  150. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  151. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  152. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  153. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  154. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  155. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  156. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  157. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  158. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  159. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  160. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  161. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  162. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  163. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  164. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  165. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  166. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  167. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  168. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  169. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  170. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  171. </ul>
  172. </li>
  173. </ul>
  174. </div>
  175. </div>
  176. </div>
  177. <div id="nav2">
  178. <a href="#" id="openToc">
  179. <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" />
  180. </a>
  181. </div>
  182. <div class="wy-grid-for-nav">
  183. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  184. <div class="wy-side-nav-search">
  185. <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
  186. <div role="search">
  187. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  188. <input type="text" name="q" placeholder="Search docs" />
  189. <input type="hidden" name="check_keywords" value="yes" />
  190. <input type="hidden" name="area" value="default" />
  191. </form>
  192. </div>
  193. </div>
  194. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  195. <ul>
  196. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  197. </ul>
  198. <ul>
  199. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  200. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  201. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  202. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  203. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  204. </ul>
  205. </li>
  206. </ul>
  207. <ul>
  208. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  209. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  210. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  211. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  212. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  213. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  214. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  215. </ul>
  216. </li>
  217. </ul>
  218. <ul>
  219. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  220. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  221. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  222. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  223. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  224. </ul>
  225. </li>
  226. </ul>
  227. <ul>
  228. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  229. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  230. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  231. </ul>
  232. </li>
  233. </ul>
  234. <ul>
  235. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  236. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  237. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  238. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  239. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  240. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  241. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  242. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  243. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  244. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  245. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  246. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  247. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  248. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  249. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  250. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  251. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  252. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  253. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  254. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  255. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  256. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  257. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  258. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  259. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  260. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  261. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  262. </ul>
  263. </li>
  264. </ul>
  265. <ul>
  266. <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
  267. <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
  268. <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
  269. <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
  270. <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
  271. <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
  272. <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
  273. <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
  274. <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
  275. <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
  276. <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
  277. <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
  278. <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
  279. <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
  280. <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
  281. <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
  282. <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
  283. <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
  284. <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
  285. <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
  286. <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
  287. <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
  288. <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
  289. <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
  290. <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
  291. <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
  292. <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
  293. <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
  294. <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
  295. <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  296. <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
  297. </ul>
  298. </li>
  299. </ul>
  300. <ul class="current">
  301. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
  302. <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
  303. <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
  304. <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
  305. <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
  306. <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li>
  307. <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
  308. <li class="toctree-l2"><a class="reference internal" href="query_builder.html">Query Builder Class</a></li>
  309. <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
  310. <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
  311. <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
  312. <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
  313. <li class="toctree-l2 current"><a class="current reference internal" href="#">Database Manipulation with Database Forge</a></li>
  314. <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
  315. <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
  316. </ul>
  317. </li>
  318. </ul>
  319. <ul>
  320. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  321. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  322. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  323. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  324. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  325. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  326. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  327. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  328. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  329. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  330. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  331. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  332. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  333. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  334. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  335. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  336. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  337. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  338. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  339. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  340. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  341. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  342. </ul>
  343. </li>
  344. </ul>
  345. </div>
  346. &nbsp;
  347. </nav>
  348. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  349. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  350. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  351. <a href="../index.html">CodeIgniter</a>
  352. </nav>
  353. <div class="wy-nav-content">
  354. <div class="rst-content">
  355. <div role="navigation" aria-label="breadcrumbs navigation">
  356. <ul class="wy-breadcrumbs">
  357. <li><a href="../index.html">Docs</a> &raquo;</li>
  358. <li><a href="index.html">Database Reference</a> &raquo;</li>
  359. <li>Database Forge Class</li>
  360. <li class="wy-breadcrumbs-aside">
  361. </li>
  362. <div style="float:right;margin-left:5px;" id="closeMe">
  363. <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
  364. </div>
  365. </ul>
  366. <hr/>
  367. </div>
  368. <div role="main" class="document">
  369. <div class="section" id="database-forge-class">
  370. <h1><a class="toc-backref" href="#id1">Database Forge Class</a><a class="headerlink" href="#database-forge-class" title="Permalink to this headline">¶</a></h1>
  371. <p>The Database Forge Class contains methods that help you manage your
  372. database.</p>
  373. <div class="contents topic" id="table-of-contents">
  374. <p class="topic-title first">Table of Contents</p>
  375. <ul class="simple">
  376. <li><a class="reference internal" href="#database-forge-class" id="id1">Database Forge Class</a><ul>
  377. <li><a class="reference internal" href="#initializing-the-forge-class" id="id2">Initializing the Forge Class</a></li>
  378. <li><a class="reference internal" href="#creating-and-dropping-databases" id="id3">Creating and Dropping Databases</a></li>
  379. <li><a class="reference internal" href="#creating-and-dropping-tables" id="id4">Creating and Dropping Tables</a><ul>
  380. <li><a class="reference internal" href="#adding-fields" id="id5">Adding fields</a></li>
  381. <li><a class="reference internal" href="#adding-keys" id="id6">Adding Keys</a></li>
  382. <li><a class="reference internal" href="#creating-a-table" id="id7">Creating a table</a></li>
  383. <li><a class="reference internal" href="#dropping-a-table" id="id8">Dropping a table</a></li>
  384. <li><a class="reference internal" href="#renaming-a-table" id="id9">Renaming a table</a></li>
  385. </ul>
  386. </li>
  387. <li><a class="reference internal" href="#modifying-tables" id="id10">Modifying Tables</a><ul>
  388. <li><a class="reference internal" href="#adding-a-column-to-a-table" id="id11">Adding a Column to a Table</a></li>
  389. <li><a class="reference internal" href="#dropping-a-column-from-a-table" id="id12">Dropping a Column From a Table</a></li>
  390. <li><a class="reference internal" href="#modifying-a-column-in-a-table" id="id13">Modifying a Column in a Table</a></li>
  391. </ul>
  392. </li>
  393. <li><a class="reference internal" href="#class-reference" id="id14">Class Reference</a></li>
  394. </ul>
  395. </li>
  396. </ul>
  397. </div>
  398. <div class="section" id="initializing-the-forge-class">
  399. <h2><a class="toc-backref" href="#id2">Initializing the Forge Class</a><a class="headerlink" href="#initializing-the-forge-class" title="Permalink to this headline">¶</a></h2>
  400. <div class="admonition important">
  401. <p class="first admonition-title">Important</p>
  402. <p class="last">In order to initialize the Forge class, your database
  403. driver must already be running, since the forge class relies on it.</p>
  404. </div>
  405. <p>Load the Forge Class as follows:</p>
  406. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="p">()</span>
  407. </pre></div>
  408. </div>
  409. <p>You can also pass another database object to the DB Forge loader, in case
  410. the database you want to manage isn’t the default one:</p>
  411. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">myforge</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">other_db</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span>
  412. </pre></div>
  413. </div>
  414. <p>In the above example, we’re passing a custom database object as the first
  415. parameter and then tell it to return the dbforge object, instead of
  416. assigning it directly to <code class="docutils literal"><span class="pre">$this-&gt;dbforge</span></code>.</p>
  417. <div class="admonition note">
  418. <p class="first admonition-title">Note</p>
  419. <p class="last">Both of the parameters can be used individually, just pass an empty
  420. value as the first one if you wish to skip it.</p>
  421. </div>
  422. <p>Once initialized you will access the methods using the <code class="docutils literal"><span class="pre">$this-&gt;dbforge</span></code>
  423. object:</p>
  424. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">some_method</span><span class="p">();</span>
  425. </pre></div>
  426. </div>
  427. </div>
  428. <div class="section" id="creating-and-dropping-databases">
  429. <h2><a class="toc-backref" href="#id3">Creating and Dropping Databases</a><a class="headerlink" href="#creating-and-dropping-databases" title="Permalink to this headline">¶</a></h2>
  430. <p><strong>$this-&gt;dbforge-&gt;create_database(‘db_name’)</strong></p>
  431. <p>Permits you to create the database specified in the first parameter.
  432. Returns TRUE/FALSE based on success or failure:</p>
  433. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">create_database</span><span class="p">(</span><span class="s1">&#39;my_db&#39;</span><span class="p">))</span>
  434. <span class="p">{</span>
  435. <span class="k">echo</span> <span class="s1">&#39;Database created!&#39;</span><span class="p">;</span>
  436. <span class="p">}</span>
  437. </pre></div>
  438. </div>
  439. <p><strong>$this-&gt;dbforge-&gt;drop_database(‘db_name’)</strong></p>
  440. <p>Permits you to drop the database specified in the first parameter.
  441. Returns TRUE/FALSE based on success or failure:</p>
  442. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">drop_database</span><span class="p">(</span><span class="s1">&#39;my_db&#39;</span><span class="p">))</span>
  443. <span class="p">{</span>
  444. <span class="k">echo</span> <span class="s1">&#39;Database deleted!&#39;</span><span class="p">;</span>
  445. <span class="p">}</span>
  446. </pre></div>
  447. </div>
  448. </div>
  449. <div class="section" id="creating-and-dropping-tables">
  450. <h2><a class="toc-backref" href="#id4">Creating and Dropping Tables</a><a class="headerlink" href="#creating-and-dropping-tables" title="Permalink to this headline">¶</a></h2>
  451. <p>There are several things you may wish to do when creating tables. Add
  452. fields, add keys to the table, alter columns. CodeIgniter provides a
  453. mechanism for this.</p>
  454. <div class="section" id="adding-fields">
  455. <h3><a class="toc-backref" href="#id5">Adding fields</a><a class="headerlink" href="#adding-fields" title="Permalink to this headline">¶</a></h3>
  456. <p>Fields are created via an associative array. Within the array you must
  457. include a ‘type’ key that relates to the datatype of the field. For
  458. example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR)
  459. also require a ‘constraint’ key.</p>
  460. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  461. <span class="s1">&#39;users&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  462. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;VARCHAR&#39;</span><span class="p">,</span>
  463. <span class="s1">&#39;constraint&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;100&#39;</span><span class="p">,</span>
  464. <span class="p">),</span>
  465. <span class="p">);</span>
  466. <span class="c1">// will translate to &quot;users VARCHAR(100)&quot; when the field is added.</span>
  467. </pre></div>
  468. </div>
  469. <p>Additionally, the following key/values can be used:</p>
  470. <ul class="simple">
  471. <li>unsigned/true : to generate “UNSIGNED” in the field definition.</li>
  472. <li>default/value : to generate a default value in the field definition.</li>
  473. <li>null/true : to generate “NULL” in the field definition. Without this,
  474. the field will default to “NOT NULL”.</li>
  475. <li>auto_increment/true : generates an auto_increment flag on the
  476. field. Note that the field type must be a type that supports this,
  477. such as integer.</li>
  478. <li>unique/true : to generate a unique key for the field definition.</li>
  479. </ul>
  480. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  481. <span class="s1">&#39;blog_id&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  482. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;INT&#39;</span><span class="p">,</span>
  483. <span class="s1">&#39;constraint&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span><span class="p">,</span>
  484. <span class="s1">&#39;unsigned&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">,</span>
  485. <span class="s1">&#39;auto_increment&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span>
  486. <span class="p">),</span>
  487. <span class="s1">&#39;blog_title&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  488. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;VARCHAR&#39;</span><span class="p">,</span>
  489. <span class="s1">&#39;constraint&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;100&#39;</span><span class="p">,</span>
  490. <span class="s1">&#39;unique&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">,</span>
  491. <span class="p">),</span>
  492. <span class="s1">&#39;blog_author&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  493. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span><span class="s1">&#39;VARCHAR&#39;</span><span class="p">,</span>
  494. <span class="s1">&#39;constraint&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;100&#39;</span><span class="p">,</span>
  495. <span class="s1">&#39;default&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;King of Town&#39;</span><span class="p">,</span>
  496. <span class="p">),</span>
  497. <span class="s1">&#39;blog_description&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  498. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;TEXT&#39;</span><span class="p">,</span>
  499. <span class="s1">&#39;null&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">,</span>
  500. <span class="p">),</span>
  501. <span class="p">);</span>
  502. </pre></div>
  503. </div>
  504. <p>After the fields have been defined, they can be added using
  505. <code class="docutils literal"><span class="pre">$this-&gt;dbforge-&gt;add_field($fields);</span></code> followed by a call to the
  506. <code class="docutils literal"><span class="pre">create_table()</span></code> method.</p>
  507. <p><strong>$this-&gt;dbforge-&gt;add_field()</strong></p>
  508. <p>The add fields method will accept the above array.</p>
  509. <div class="section" id="passing-strings-as-fields">
  510. <h4>Passing strings as fields<a class="headerlink" href="#passing-strings-as-fields" title="Permalink to this headline">¶</a></h4>
  511. <p>If you know exactly how you want a field to be created, you can pass the
  512. string into the field definitions with add_field()</p>
  513. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_field</span><span class="p">(</span><span class="s2">&quot;label varchar(100) NOT NULL DEFAULT &#39;default label&#39;&quot;</span><span class="p">);</span>
  514. </pre></div>
  515. </div>
  516. <div class="admonition note">
  517. <p class="first admonition-title">Note</p>
  518. <p class="last">Passing raw strings as fields cannot be followed by <code class="docutils literal"><span class="pre">add_key()</span></code> calls on those fields.</p>
  519. </div>
  520. <div class="admonition note">
  521. <p class="first admonition-title">Note</p>
  522. <p class="last">Multiple calls to add_field() are cumulative.</p>
  523. </div>
  524. </div>
  525. <div class="section" id="creating-an-id-field">
  526. <h4>Creating an id field<a class="headerlink" href="#creating-an-id-field" title="Permalink to this headline">¶</a></h4>
  527. <p>There is a special exception for creating id fields. A field with type
  528. id will automatically be assigned as an INT(9) auto_incrementing
  529. Primary Key.</p>
  530. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_field</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">);</span>
  531. <span class="c1">// gives id INT(9) NOT NULL AUTO_INCREMENT</span>
  532. </pre></div>
  533. </div>
  534. </div>
  535. </div>
  536. <div class="section" id="adding-keys">
  537. <h3><a class="toc-backref" href="#id6">Adding Keys</a><a class="headerlink" href="#adding-keys" title="Permalink to this headline">¶</a></h3>
  538. <p>Generally speaking, you’ll want your table to have Keys. This is
  539. accomplished with $this-&gt;dbforge-&gt;add_key(‘field’). An optional second
  540. parameter set to TRUE will make it a primary key. Note that add_key()
  541. must be followed by a call to create_table().</p>
  542. <p>Multiple column non-primary keys must be sent as an array. Sample output
  543. below is for MySQL.</p>
  544. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_key</span><span class="p">(</span><span class="s1">&#39;blog_id&#39;</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span>
  545. <span class="c1">// gives PRIMARY KEY `blog_id` (`blog_id`)</span>
  546. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_key</span><span class="p">(</span><span class="s1">&#39;blog_id&#39;</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span>
  547. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_key</span><span class="p">(</span><span class="s1">&#39;site_id&#39;</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span>
  548. <span class="c1">// gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`)</span>
  549. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_key</span><span class="p">(</span><span class="s1">&#39;blog_name&#39;</span><span class="p">);</span>
  550. <span class="c1">// gives KEY `blog_name` (`blog_name`)</span>
  551. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_key</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;blog_name&#39;</span><span class="p">,</span> <span class="s1">&#39;blog_label&#39;</span><span class="p">));</span>
  552. <span class="c1">// gives KEY `blog_name_blog_label` (`blog_name`, `blog_label`)</span>
  553. </pre></div>
  554. </div>
  555. </div>
  556. <div class="section" id="creating-a-table">
  557. <h3><a class="toc-backref" href="#id7">Creating a table</a><a class="headerlink" href="#creating-a-table" title="Permalink to this headline">¶</a></h3>
  558. <p>After fields and keys have been declared, you can create a new table
  559. with</p>
  560. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">create_table</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">);</span>
  561. <span class="c1">// gives CREATE TABLE table_name</span>
  562. </pre></div>
  563. </div>
  564. <p>An optional second parameter set to TRUE adds an “IF NOT EXISTS” clause
  565. into the definition</p>
  566. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">create_table</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span> <span class="k">TRUE</span><span class="p">);</span>
  567. <span class="c1">// gives CREATE TABLE IF NOT EXISTS table_name</span>
  568. </pre></div>
  569. </div>
  570. <p>You could also pass optional table attributes, such as MySQL’s <code class="docutils literal"><span class="pre">ENGINE</span></code>:</p>
  571. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$attributes</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;ENGINE&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;InnoDB&#39;</span><span class="p">);</span>
  572. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">create_table</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span> <span class="k">FALSE</span><span class="p">,</span> <span class="nv">$attributes</span><span class="p">);</span>
  573. <span class="c1">// produces: CREATE TABLE `table_name` (...) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci</span>
  574. </pre></div>
  575. </div>
  576. <div class="admonition note">
  577. <p class="first admonition-title">Note</p>
  578. <p class="last">Unless you specify the <code class="docutils literal"><span class="pre">CHARACTER</span> <span class="pre">SET</span></code> and/or <code class="docutils literal"><span class="pre">COLLATE</span></code> attributes,
  579. <code class="docutils literal"><span class="pre">create_table()</span></code> will always add them with your configured <em>char_set</em>
  580. and <em>dbcollat</em> values, as long as they are not empty (MySQL only).</p>
  581. </div>
  582. </div>
  583. <div class="section" id="dropping-a-table">
  584. <h3><a class="toc-backref" href="#id8">Dropping a table</a><a class="headerlink" href="#dropping-a-table" title="Permalink to this headline">¶</a></h3>
  585. <p>Execute a DROP TABLE statement and optionally add an IF EXISTS clause.</p>
  586. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Produces: DROP TABLE table_name</span>
  587. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">drop_table</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">);</span>
  588. <span class="c1">// Produces: DROP TABLE IF EXISTS table_name</span>
  589. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">drop_table</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span><span class="k">TRUE</span><span class="p">);</span>
  590. </pre></div>
  591. </div>
  592. </div>
  593. <div class="section" id="renaming-a-table">
  594. <h3><a class="toc-backref" href="#id9">Renaming a table</a><a class="headerlink" href="#renaming-a-table" title="Permalink to this headline">¶</a></h3>
  595. <p>Executes a TABLE rename</p>
  596. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">rename_table</span><span class="p">(</span><span class="s1">&#39;old_table_name&#39;</span><span class="p">,</span> <span class="s1">&#39;new_table_name&#39;</span><span class="p">);</span>
  597. <span class="c1">// gives ALTER TABLE old_table_name RENAME TO new_table_name</span>
  598. </pre></div>
  599. </div>
  600. </div>
  601. </div>
  602. <div class="section" id="modifying-tables">
  603. <h2><a class="toc-backref" href="#id10">Modifying Tables</a><a class="headerlink" href="#modifying-tables" title="Permalink to this headline">¶</a></h2>
  604. <div class="section" id="adding-a-column-to-a-table">
  605. <h3><a class="toc-backref" href="#id11">Adding a Column to a Table</a><a class="headerlink" href="#adding-a-column-to-a-table" title="Permalink to this headline">¶</a></h3>
  606. <p><strong>$this-&gt;dbforge-&gt;add_column()</strong></p>
  607. <p>The <code class="docutils literal"><span class="pre">add_column()</span></code> method is used to modify an existing table. It
  608. accepts the same field array as above, and can be used for an unlimited
  609. number of additional fields.</p>
  610. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  611. <span class="s1">&#39;preferences&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;TEXT&#39;</span><span class="p">)</span>
  612. <span class="p">);</span>
  613. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">add_column</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span> <span class="nv">$fields</span><span class="p">);</span>
  614. <span class="c1">// Executes: ALTER TABLE table_name ADD preferences TEXT</span>
  615. </pre></div>
  616. </div>
  617. <p>If you are using MySQL or CUBIRD, then you can take advantage of their
  618. AFTER and FIRST clauses to position the new column.</p>
  619. <p>Examples:</p>
  620. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="c1">// Will place the new column after the `another_field` column:</span>
  621. <span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  622. <span class="s1">&#39;preferences&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;TEXT&#39;</span><span class="p">,</span> <span class="s1">&#39;after&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;another_field&#39;</span><span class="p">)</span>
  623. <span class="p">);</span>
  624. <span class="c1">// Will place the new column at the start of the table definition:</span>
  625. <span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  626. <span class="s1">&#39;preferences&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;TEXT&#39;</span><span class="p">,</span> <span class="s1">&#39;first&#39;</span> <span class="o">=&gt;</span> <span class="k">TRUE</span><span class="p">)</span>
  627. <span class="p">);</span>
  628. </pre></div>
  629. </div>
  630. </div>
  631. <div class="section" id="dropping-a-column-from-a-table">
  632. <h3><a class="toc-backref" href="#id12">Dropping a Column From a Table</a><a class="headerlink" href="#dropping-a-column-from-a-table" title="Permalink to this headline">¶</a></h3>
  633. <p><strong>$this-&gt;dbforge-&gt;drop_column()</strong></p>
  634. <p>Used to remove a column from a table.</p>
  635. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">drop_column</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span> <span class="s1">&#39;column_to_drop&#39;</span><span class="p">);</span>
  636. </pre></div>
  637. </div>
  638. </div>
  639. <div class="section" id="modifying-a-column-in-a-table">
  640. <h3><a class="toc-backref" href="#id13">Modifying a Column in a Table</a><a class="headerlink" href="#modifying-a-column-in-a-table" title="Permalink to this headline">¶</a></h3>
  641. <p><strong>$this-&gt;dbforge-&gt;modify_column()</strong></p>
  642. <p>The usage of this method is identical to <code class="docutils literal"><span class="pre">add_column()</span></code>, except it
  643. alters an existing column rather than adding a new one. In order to
  644. change the name you can add a “name” key into the field defining array.</p>
  645. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
  646. <span class="s1">&#39;old_name&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span>
  647. <span class="s1">&#39;name&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;new_name&#39;</span><span class="p">,</span>
  648. <span class="s1">&#39;type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;TEXT&#39;</span><span class="p">,</span>
  649. <span class="p">),</span>
  650. <span class="p">);</span>
  651. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">dbforge</span><span class="o">-&gt;</span><span class="na">modify_column</span><span class="p">(</span><span class="s1">&#39;table_name&#39;</span><span class="p">,</span> <span class="nv">$fields</span><span class="p">);</span>
  652. <span class="c1">// gives ALTER TABLE table_name CHANGE old_name new_name TEXT</span>
  653. </pre></div>
  654. </div>
  655. </div>
  656. </div>
  657. <div class="section" id="class-reference">
  658. <h2><a class="toc-backref" href="#id14">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2>
  659. <dl class="class">
  660. <dt id="CI_DB_forge">
  661. <em class="property">class </em><code class="descname">CI_DB_forge</code><a class="headerlink" href="#CI_DB_forge" title="Permalink to this definition">¶</a></dt>
  662. <dd><dl class="method">
  663. <dt id="CI_DB_forge::add_column">
  664. <code class="descname">add_column</code><span class="sig-paren">(</span><em>$table</em><span class="optional">[</span>, <em>$field = array()</em><span class="optional">[</span>, <em>$_after = NULL</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::add_column" title="Permalink to this definition">¶</a></dt>
  665. <dd><table class="docutils field-list" frame="void" rules="none">
  666. <col class="field-name" />
  667. <col class="field-body" />
  668. <tbody valign="top">
  669. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  670. <li><strong>$table</strong> (<em>string</em>) – Table name to add the column to</li>
  671. <li><strong>$field</strong> (<em>array</em>) – Column definition(s)</li>
  672. <li><strong>$_after</strong> (<em>string</em>) – Column for AFTER clause (deprecated)</li>
  673. </ul>
  674. </td>
  675. </tr>
  676. <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>
  677. </td>
  678. </tr>
  679. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  680. </td>
  681. </tr>
  682. </tbody>
  683. </table>
  684. <p>Adds a column to a table. Usage: See <a class="reference internal" href="#adding-a-column-to-a-table">Adding a Column to a Table</a>.</p>
  685. </dd></dl>
  686. <dl class="method">
  687. <dt id="CI_DB_forge::add_field">
  688. <code class="descname">add_field</code><span class="sig-paren">(</span><em>$field</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::add_field" title="Permalink to this definition">¶</a></dt>
  689. <dd><table class="docutils field-list" frame="void" rules="none">
  690. <col class="field-name" />
  691. <col class="field-body" />
  692. <tbody valign="top">
  693. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  694. <li><strong>$field</strong> (<em>array</em>) – Field definition to add</li>
  695. </ul>
  696. </td>
  697. </tr>
  698. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_forge instance (method chaining)</p>
  699. </td>
  700. </tr>
  701. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_forge</p>
  702. </td>
  703. </tr>
  704. </tbody>
  705. </table>
  706. <p>Adds a field to the set that will be used to create a table. Usage: See <a class="reference internal" href="#adding-fields">Adding fields</a>.</p>
  707. </dd></dl>
  708. <dl class="method">
  709. <dt id="CI_DB_forge::add_key">
  710. <code class="descname">add_key</code><span class="sig-paren">(</span><em>$key</em><span class="optional">[</span>, <em>$primary = FALSE</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::add_key" title="Permalink to this definition">¶</a></dt>
  711. <dd><table class="docutils field-list" frame="void" rules="none">
  712. <col class="field-name" />
  713. <col class="field-body" />
  714. <tbody valign="top">
  715. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  716. <li><strong>$key</strong> (<em>array</em>) – Name of a key field</li>
  717. <li><strong>$primary</strong> (<em>bool</em>) – Set to TRUE if it should be a primary key or a regular one</li>
  718. </ul>
  719. </td>
  720. </tr>
  721. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_DB_forge instance (method chaining)</p>
  722. </td>
  723. </tr>
  724. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_forge</p>
  725. </td>
  726. </tr>
  727. </tbody>
  728. </table>
  729. <p>Adds a key to the set that will be used to create a table. Usage: See <a class="reference internal" href="#adding-keys">Adding Keys</a>.</p>
  730. </dd></dl>
  731. <dl class="method">
  732. <dt id="CI_DB_forge::create_database">
  733. <code class="descname">create_database</code><span class="sig-paren">(</span><em>$db_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::create_database" title="Permalink to this definition">¶</a></dt>
  734. <dd><table class="docutils field-list" frame="void" rules="none">
  735. <col class="field-name" />
  736. <col class="field-body" />
  737. <tbody valign="top">
  738. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  739. <li><strong>$db_name</strong> (<em>string</em>) – Name of the database to create</li>
  740. </ul>
  741. </td>
  742. </tr>
  743. <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>
  744. </td>
  745. </tr>
  746. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  747. </td>
  748. </tr>
  749. </tbody>
  750. </table>
  751. <p>Creates a new database. Usage: See <a class="reference internal" href="#creating-and-dropping-databases">Creating and Dropping Databases</a>.</p>
  752. </dd></dl>
  753. <dl class="method">
  754. <dt id="CI_DB_forge::create_table">
  755. <code class="descname">create_table</code><span class="sig-paren">(</span><em>$table</em><span class="optional">[</span>, <em>$if_not_exists = FALSE</em><span class="optional">[</span>, <em>array $attributes = array()</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::create_table" title="Permalink to this definition">¶</a></dt>
  756. <dd><table class="docutils field-list" frame="void" rules="none">
  757. <col class="field-name" />
  758. <col class="field-body" />
  759. <tbody valign="top">
  760. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  761. <li><strong>$table</strong> (<em>string</em>) – Name of the table to create</li>
  762. <li><strong>$if_not_exists</strong> (<em>string</em>) – Set to TRUE to add an ‘IF NOT EXISTS’ clause</li>
  763. <li><strong>$attributes</strong> (<em>string</em>) – An associative array of table attributes</li>
  764. </ul>
  765. </td>
  766. </tr>
  767. <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>
  768. </td>
  769. </tr>
  770. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  771. </td>
  772. </tr>
  773. </tbody>
  774. </table>
  775. <p>Creates a new table. Usage: See <a class="reference internal" href="#creating-a-table">Creating a table</a>.</p>
  776. </dd></dl>
  777. <dl class="method">
  778. <dt id="CI_DB_forge::drop_column">
  779. <code class="descname">drop_column</code><span class="sig-paren">(</span><em>$table</em>, <em>$column_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::drop_column" title="Permalink to this definition">¶</a></dt>
  780. <dd><table class="docutils field-list" frame="void" rules="none">
  781. <col class="field-name" />
  782. <col class="field-body" />
  783. <tbody valign="top">
  784. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  785. <li><strong>$table</strong> (<em>string</em>) – Table name</li>
  786. <li><strong>$column_name</strong> (<em>array</em>) – The column name to drop</li>
  787. </ul>
  788. </td>
  789. </tr>
  790. <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>
  791. </td>
  792. </tr>
  793. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  794. </td>
  795. </tr>
  796. </tbody>
  797. </table>
  798. <p>Drops a column from a table. Usage: See <a class="reference internal" href="#dropping-a-column-from-a-table">Dropping a Column From a Table</a>.</p>
  799. </dd></dl>
  800. <dl class="method">
  801. <dt id="CI_DB_forge::drop_database">
  802. <code class="descname">drop_database</code><span class="sig-paren">(</span><em>$db_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::drop_database" title="Permalink to this definition">¶</a></dt>
  803. <dd><table class="docutils field-list" frame="void" rules="none">
  804. <col class="field-name" />
  805. <col class="field-body" />
  806. <tbody valign="top">
  807. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  808. <li><strong>$db_name</strong> (<em>string</em>) – Name of the database to drop</li>
  809. </ul>
  810. </td>
  811. </tr>
  812. <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>
  813. </td>
  814. </tr>
  815. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  816. </td>
  817. </tr>
  818. </tbody>
  819. </table>
  820. <p>Drops a database. Usage: See <a class="reference internal" href="#creating-and-dropping-databases">Creating and Dropping Databases</a>.</p>
  821. </dd></dl>
  822. <dl class="method">
  823. <dt id="CI_DB_forge::drop_table">
  824. <code class="descname">drop_table</code><span class="sig-paren">(</span><em>$table_name</em><span class="optional">[</span>, <em>$if_exists = FALSE</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::drop_table" title="Permalink to this definition">¶</a></dt>
  825. <dd><table class="docutils field-list" frame="void" rules="none">
  826. <col class="field-name" />
  827. <col class="field-body" />
  828. <tbody valign="top">
  829. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  830. <li><strong>$table</strong> (<em>string</em>) – Name of the table to drop</li>
  831. <li><strong>$if_exists</strong> (<em>string</em>) – Set to TRUE to add an ‘IF EXISTS’ clause</li>
  832. </ul>
  833. </td>
  834. </tr>
  835. <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>
  836. </td>
  837. </tr>
  838. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  839. </td>
  840. </tr>
  841. </tbody>
  842. </table>
  843. <p>Drops a table. Usage: See <a class="reference internal" href="#dropping-a-table">Dropping a table</a>.</p>
  844. </dd></dl>
  845. <dl class="method">
  846. <dt id="CI_DB_forge::modify_column">
  847. <code class="descname">modify_column</code><span class="sig-paren">(</span><em>$table</em>, <em>$field</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::modify_column" title="Permalink to this definition">¶</a></dt>
  848. <dd><table class="docutils field-list" frame="void" rules="none">
  849. <col class="field-name" />
  850. <col class="field-body" />
  851. <tbody valign="top">
  852. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  853. <li><strong>$table</strong> (<em>string</em>) – Table name</li>
  854. <li><strong>$field</strong> (<em>array</em>) – Column definition(s)</li>
  855. </ul>
  856. </td>
  857. </tr>
  858. <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>
  859. </td>
  860. </tr>
  861. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  862. </td>
  863. </tr>
  864. </tbody>
  865. </table>
  866. <p>Modifies a table column. Usage: See <a class="reference internal" href="#modifying-a-column-in-a-table">Modifying a Column in a Table</a>.</p>
  867. </dd></dl>
  868. <dl class="method">
  869. <dt id="CI_DB_forge::rename_table">
  870. <code class="descname">rename_table</code><span class="sig-paren">(</span><em>$table_name</em>, <em>$new_table_name</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_DB_forge::rename_table" title="Permalink to this definition">¶</a></dt>
  871. <dd><table class="docutils field-list" frame="void" rules="none">
  872. <col class="field-name" />
  873. <col class="field-body" />
  874. <tbody valign="top">
  875. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  876. <li><strong>$table</strong> (<em>string</em>) – Current of the table</li>
  877. <li><strong>$new_table_name</strong> (<em>string</em>) – New name of the table</li>
  878. </ul>
  879. </td>
  880. </tr>
  881. <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>
  882. </td>
  883. </tr>
  884. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  885. </td>
  886. </tr>
  887. </tbody>
  888. </table>
  889. <p>Renames a table. Usage: See <a class="reference internal" href="#renaming-a-table">Renaming a table</a>.</p>
  890. </dd></dl>
  891. </dd></dl>
  892. </div>
  893. </div>
  894. </div>
  895. <footer>
  896. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  897. <a href="utilities.html" class="btn btn-neutral float-right" title="Database Utility Class">Next <span class="fa fa-arrow-circle-right"></span></a>
  898. <a href="caching.html" class="btn btn-neutral" title="Database Caching Class"><span class="fa fa-arrow-circle-left"></span> Previous</a>
  899. </div>
  900. <hr/>
  901. <div role="contentinfo">
  902. <p>
  903. &copy; Copyright 2014 - 2019, British Columbia Institute of Technology.
  904. Last updated on Sep 19, 2019.
  905. </p>
  906. </div>
  907. 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>.
  908. </footer>
  909. </div>
  910. </div>
  911. </section>
  912. </div>
  913. <script type="text/javascript">
  914. var DOCUMENTATION_OPTIONS = {
  915. URL_ROOT:'../',
  916. VERSION:'3.1.11',
  917. COLLAPSE_INDEX:false,
  918. FILE_SUFFIX:'.html',
  919. HAS_SOURCE: false
  920. };
  921. </script>
  922. <script type="text/javascript" src="../_static/jquery.js"></script>
  923. <script type="text/javascript" src="../_static/underscore.js"></script>
  924. <script type="text/javascript" src="../_static/doctools.js"></script>
  925. <script type="text/javascript" src="../_static/js/theme.js"></script>
  926. <script type="text/javascript">
  927. jQuery(function () {
  928. SphinxRtdTheme.StickyNav.enable();
  929. });
  930. </script>
  931. </body>
  932. </html>