123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715 |
- <!DOCTYPE html>
- <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
- <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
- <title>Query Builder Class — CodeIgniter 3.1.11 documentation</title>
-
-
-
- <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
-
-
- <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
-
-
-
-
-
-
- <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
-
-
- <link rel="index" title="Index"
- href="../genindex.html"/>
- <link rel="search" title="Search" href="../search.html"/>
- <link rel="top" title="CodeIgniter 3.1.11 documentation" href="../index.html"/>
- <link rel="up" title="Database Reference" href="index.html"/>
- <link rel="next" title="Transactions" href="transactions.html"/>
- <link rel="prev" title="Query Helper Methods" href="helpers.html"/>
-
- <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
- </head>
- <body class="wy-body-for-nav" role="document">
- <div id="nav">
- <div id="nav_inner">
-
-
-
- <div id="pulldown-menu" class="ciNav">
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
- </ul>
- </li>
- </ul>
- <ul class="current">
- <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
- <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
- <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
- <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
- <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li>
- <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
- <li class="toctree-l2 current"><a class="current reference internal" href="#">Query Builder Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
- <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
- <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
- <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li>
- <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
-
- </div>
- </div>
- <div id="nav2">
- <a href="#" id="openToc">
- <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
- </a>
- </div>
- <div class="wy-grid-for-nav">
-
- <nav data-toggle="wy-nav-shift" class="wy-nav-side">
- <div class="wy-side-nav-search">
-
- <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
-
-
- <div role="search">
- <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
- <input type="text" name="q" placeholder="Search docs" />
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
- </div>
- <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
-
-
-
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/benchmark.html">Benchmarking Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/caching.html">Caching Driver</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/calendar.html">Calendaring Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/cart.html">Shopping Cart Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/config.html">Config Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/email.html">Email Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/encrypt.html">Encrypt Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/encryption.html">Encryption Library</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/file_uploading.html">File Uploading Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/form_validation.html">Form Validation</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/ftp.html">FTP Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/image_lib.html">Image Manipulation Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/input.html">Input Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/javascript.html">Javascript Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/language.html">Language Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/loader.html">Loader Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/migration.html">Migrations Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/output.html">Output Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/pagination.html">Pagination Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/parser.html">Template Parser Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/security.html">Security Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/sessions.html">Session Library</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/table.html">HTML Table Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/trackback.html">Trackback Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/typography.html">Typography Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/unit_testing.html">Unit Testing Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/uri.html">URI Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/user_agent.html">User Agent Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../libraries/zip.html">Zip Encoding Class</a></li>
- </ul>
- </li>
- </ul>
- <ul class="current">
- <li class="toctree-l1 current"><a class="reference internal" href="index.html">Database Reference</a><ul class="current">
- <li class="toctree-l2"><a class="reference internal" href="examples.html">Quick Start: Usage Examples</a></li>
- <li class="toctree-l2"><a class="reference internal" href="configuration.html">Database Configuration</a></li>
- <li class="toctree-l2"><a class="reference internal" href="connecting.html">Connecting to a Database</a></li>
- <li class="toctree-l2"><a class="reference internal" href="queries.html">Running Queries</a></li>
- <li class="toctree-l2"><a class="reference internal" href="results.html">Generating Query Results</a></li>
- <li class="toctree-l2"><a class="reference internal" href="helpers.html">Query Helper Functions</a></li>
- <li class="toctree-l2 current"><a class="current reference internal" href="#">Query Builder Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="transactions.html">Transactions</a></li>
- <li class="toctree-l2"><a class="reference internal" href="metadata.html">Getting MetaData</a></li>
- <li class="toctree-l2"><a class="reference internal" href="call_function.html">Custom Function Calls</a></li>
- <li class="toctree-l2"><a class="reference internal" href="caching.html">Query Caching</a></li>
- <li class="toctree-l2"><a class="reference internal" href="forge.html">Database Manipulation with Database Forge</a></li>
- <li class="toctree-l2"><a class="reference internal" href="utilities.html">Database Utilities Class</a></li>
- <li class="toctree-l2"><a class="reference internal" href="db_driver_reference.html">Database Driver Reference</a></li>
- </ul>
- </li>
- </ul>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
- <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
- </ul>
- </li>
- </ul>
-
-
- </div>
-
- </nav>
- <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
-
- <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
- <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
- <a href="../index.html">CodeIgniter</a>
- </nav>
-
- <div class="wy-nav-content">
- <div class="rst-content">
- <div role="navigation" aria-label="breadcrumbs navigation">
- <ul class="wy-breadcrumbs">
- <li><a href="../index.html">Docs</a> »</li>
-
- <li><a href="index.html">Database Reference</a> »</li>
-
- <li>Query Builder Class</li>
- <li class="wy-breadcrumbs-aside">
-
- </li>
- <div style="float:right;margin-left:5px;" id="closeMe">
- <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
- </div>
- </ul>
- <hr/>
- </div>
- <div role="main" class="document">
-
- <div class="section" id="query-builder-class">
- <h1>Query Builder Class<a class="headerlink" href="#query-builder-class" title="Permalink to this headline">¶</a></h1>
- <p>CodeIgniter gives you access to a Query Builder class. This pattern
- allows information to be retrieved, inserted, and updated in your
- database with minimal scripting. In some cases only one or two lines
- of code are necessary to perform a database action.
- CodeIgniter does not require that each database table be its own class
- file. It instead provides a more simplified interface.</p>
- <p>Beyond simplicity, a major benefit to using the Query Builder features
- is that it allows you to create database independent applications, since
- the query syntax is generated by each database adapter. It also allows
- for safer queries, since the values are escaped automatically by the
- system.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">If you intend to write your own queries you can disable this
- class in your database config file, allowing the core database library
- and adapter to utilize fewer resources.</p>
- </div>
- <div class="contents local topic" id="contents">
- <ul class="simple">
- <li><a class="reference internal" href="#selecting-data" id="id1">Selecting Data</a></li>
- <li><a class="reference internal" href="#looking-for-specific-data" id="id2">Looking for Specific Data</a></li>
- <li><a class="reference internal" href="#looking-for-similar-data" id="id3">Looking for Similar Data</a></li>
- <li><a class="reference internal" href="#ordering-results" id="id4">Ordering results</a></li>
- <li><a class="reference internal" href="#limiting-or-counting-results" id="id5">Limiting or Counting Results</a></li>
- <li><a class="reference internal" href="#query-grouping" id="id6">Query grouping</a></li>
- <li><a class="reference internal" href="#inserting-data" id="id7">Inserting Data</a></li>
- <li><a class="reference internal" href="#updating-data" id="id8">Updating Data</a></li>
- <li><a class="reference internal" href="#deleting-data" id="id9">Deleting Data</a></li>
- <li><a class="reference internal" href="#method-chaining" id="id10">Method Chaining</a></li>
- <li><a class="reference internal" href="#query-builder-caching" id="id11">Query Builder Caching</a></li>
- <li><a class="reference internal" href="#resetting-query-builder" id="id12">Resetting Query Builder</a></li>
- <li><a class="reference internal" href="#class-reference" id="id13">Class Reference</a></li>
- </ul>
- </div>
- <div class="section" id="selecting-data">
- <h2><a class="toc-backref" href="#id1">Selecting Data</a><a class="headerlink" href="#selecting-data" title="Permalink to this headline">¶</a></h2>
- <p>The following functions allow you to build SQL <strong>SELECT</strong> statements.</p>
- <p><strong>$this->db->get()</strong></p>
- <p>Runs the selection query and returns the result. Can be used by itself
- to retrieve all records from a table:</p>
- <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>
- </pre></div>
- </div>
- <p>The second and third parameters enable you to set a limit and offset
- clause:</p>
- <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>
- <span class="c1">// Executes: SELECT * FROM mytable LIMIT 20, 10</span>
- <span class="c1">// (in MySQL. Other databases have slightly different syntax)</span>
- </pre></div>
- </div>
- <p>You’ll notice that the above function is assigned to a variable named
- $query, which can be used to show the results:</p>
- <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="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>
- <span class="p">{</span>
- <span class="k">echo</span> <span class="nv">$row</span><span class="o">-></span><span class="na">title</span><span class="p">;</span>
- <span class="p">}</span>
- </pre></div>
- </div>
- <p>Please visit the <a class="reference internal" href="results.html"><span class="doc">result functions</span></a> page for a full
- discussion regarding result generation.</p>
- <p><strong>$this->db->get_compiled_select()</strong></p>
- <p>Compiles the selection query just like <strong>$this->db->get()</strong> but does not <em>run</em>
- the query. This method simply returns the SQL query as a string.</p>
- <p>Example:</p>
- <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>
- <span class="k">echo</span> <span class="nv">$sql</span><span class="p">;</span>
- <span class="c1">// Prints string: SELECT * FROM mytable</span>
- </pre></div>
- </div>
- <p>The second parameter enables you to set whether or not the query builder query
- will be reset (by default it will be reset, just like when using <cite>$this->db->get()</cite>):</p>
- <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>
- <span class="c1">// Prints string: SELECT * FROM mytable LIMIT 20, 10</span>
- <span class="c1">// (in MySQL. Other databases have slightly different syntax)</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">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>
- <span class="c1">// Prints string: SELECT title, content, date FROM mytable LIMIT 20, 10</span>
- </pre></div>
- </div>
- <p>The key thing to notice in the above example is that the second query did not
- utilize <strong>$this->db->from()</strong> and did not pass a table name into the first
- parameter. The reason for this outcome is because the query has not been
- executed using <strong>$this->db->get()</strong> which resets values or reset directly
- using <strong>$this->db->reset_query()</strong>.</p>
- <p><strong>$this->db->get_where()</strong></p>
- <p>Identical to the above function except that it permits you to add a
- “where” clause in the second parameter, instead of using the db->where()
- function:</p>
- <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>
- </pre></div>
- </div>
- <p>Please read the about the where function below for more information.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">get_where() was formerly known as getwhere(), which has been removed</p>
- </div>
- <p><strong>$this->db->select()</strong></p>
- <p>Permits you to write the SELECT portion of your query:</p>
- <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>
- <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">// Executes: SELECT title, content, date FROM mytable</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">If you are selecting all (*) from a table you do not need to
- use this function. When omitted, CodeIgniter assumes that you wish
- to select all fields and automatically adds ‘SELECT *’.</p>
- </div>
- <p><code class="docutils literal"><span class="pre">$this->db->select()</span></code> accepts an optional second parameter. If you set it
- to FALSE, CodeIgniter will not try to protect your field or table names.
- This is useful if you need a compound select statement where automatic
- escaping of fields may break them.</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->select_max()</strong></p>
- <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
- include a second parameter to rename the resulting field.</p>
- <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>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->select_min()</strong></p>
- <p>Writes a “SELECT MIN(field)” portion for your query. As with
- select_max(), You can optionally include a second parameter to rename
- the resulting field.</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->select_avg()</strong></p>
- <p>Writes a “SELECT AVG(field)” portion for your query. As with
- select_max(), You can optionally include a second parameter to rename
- the resulting field.</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->select_sum()</strong></p>
- <p>Writes a “SELECT SUM(field)” portion for your query. As with
- select_max(), You can optionally include a second parameter to rename
- the resulting field.</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->from()</strong></p>
- <p>Permits you to write the FROM portion of your query:</p>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">As shown earlier, the FROM portion of your query can be specified
- in the $this->db->get() function, so use whichever method you prefer.</p>
- </div>
- <p><strong>$this->db->join()</strong></p>
- <p>Permits you to write the JOIN portion of your query:</p>
- <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="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>
- <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="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:</span>
- <span class="c1">// SELECT * FROM blogs JOIN comments ON comments.id = blogs.id</span>
- </pre></div>
- </div>
- <p>Multiple function calls can be made if you need several joins in one
- query.</p>
- <p>If you need a specific type of JOIN you can specify it via the third
- parameter of the function. Options are: left, right, outer, inner, left
- outer, and right outer.</p>
- <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>
- <span class="c1">// Produces: LEFT JOIN comments ON comments.id = blogs.id</span>
- </pre></div>
- </div>
- </div>
- <div class="section" id="looking-for-specific-data">
- <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>
- <p><strong>$this->db->where()</strong></p>
- <p>This function enables you to set <strong>WHERE</strong> clauses using one of four
- methods:</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values passed to this function are escaped automatically,
- producing safer queries.</p>
- </div>
- <ol class="arabic">
- <li><p class="first"><strong>Simple key/value method:</strong></p>
- <blockquote>
- <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>
- </pre></div>
- </div>
- <p>Notice that the equal sign is added for you.</p>
- <p>If you use multiple function calls they will be chained together with
- AND between them:</p>
- <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="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>
- <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>
- <span class="c1">// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'</span>
- </pre></div>
- </div>
- </div></blockquote>
- </li>
- <li><p class="first"><strong>Custom key/value method:</strong></p>
- <blockquote>
- <div><p>You can include an operator in the first parameter in order to
- control the comparison:</p>
- <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="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>
- </pre></div>
- </div>
- </div></blockquote>
- </li>
- <li><p class="first"><strong>Associative array method:</strong></p>
- <blockquote>
- <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>
- <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>
- <span class="c1">// Produces: WHERE name = 'Joe' AND title = 'boss' AND status = 'active'</span>
- </pre></div>
- </div>
- <p>You can include your own operators using this method as well:</p>
- <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>
- <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>
- </pre></div>
- </div>
- </div></blockquote>
- </li>
- <li><dl class="first docutils">
- <dt><strong>Custom string:</strong></dt>
- <dd><p class="first">You can write your own clauses manually:</p>
- <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>
- <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>
- </pre></div>
- </div>
- </dd>
- </dl>
- </li>
- </ol>
- <p><code class="docutils literal"><span class="pre">$this->db->where()</span></code> accepts an optional third parameter. If you set it to
- FALSE, CodeIgniter will not try to protect your field or table names.</p>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->or_where()</strong></p>
- <p>This function is identical to the one above, except that multiple
- instances are joined by OR:</p>
- <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="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>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">or_where() was formerly known as orwhere(), which has been
- removed.</p>
- </div>
- <p><strong>$this->db->where_in()</strong></p>
- <p>Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with AND if
- appropriate</p>
- <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>
- <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>
- <span class="c1">// Produces: WHERE username IN ('Frank', 'Todd', 'James')</span>
- </pre></div>
- </div>
- <p><strong>$this->db->or_where_in()</strong></p>
- <p>Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with OR if
- appropriate</p>
- <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>
- <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>
- <span class="c1">// Produces: OR username IN ('Frank', 'Todd', 'James')</span>
- </pre></div>
- </div>
- <p><strong>$this->db->where_not_in()</strong></p>
- <p>Generates a WHERE field NOT IN (‘item’, ‘item’) SQL query joined with
- AND if appropriate</p>
- <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>
- <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>
- <span class="c1">// Produces: WHERE username NOT IN ('Frank', 'Todd', 'James')</span>
- </pre></div>
- </div>
- <p><strong>$this->db->or_where_not_in()</strong></p>
- <p>Generates a WHERE field NOT IN (‘item’, ‘item’) SQL query joined with OR
- if appropriate</p>
- <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>
- <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>
- <span class="c1">// Produces: OR username NOT IN ('Frank', 'Todd', 'James')</span>
- </pre></div>
- </div>
- </div>
- <div class="section" id="looking-for-similar-data">
- <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>
- <p><strong>$this->db->like()</strong></p>
- <p>This method enables you to generate <strong>LIKE</strong> clauses, useful for doing
- searches.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values passed to this method are escaped automatically.</p>
- </div>
- <ol class="arabic">
- <li><p class="first"><strong>Simple key/value method:</strong></p>
- <blockquote>
- <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>
- <span class="c1">// Produces: WHERE `title` LIKE '%match%' ESCAPE '!'</span>
- </pre></div>
- </div>
- <p>If you use multiple method calls they will be chained together with
- AND between them:</p>
- <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">like</span><span class="p">(</span><span class="s1">'body'</span><span class="p">,</span> <span class="s1">'match'</span><span class="p">);</span>
- <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' AND `body` LIKE '%match% ESCAPE '!'</span>
- </pre></div>
- </div>
- <p>If you want to control where the wildcard (%) is placed, you can use
- an optional third argument. Your options are ‘before’, ‘after’, ‘none’ and
- ‘both’ (which is the default).</p>
- <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>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- </div></blockquote>
- </li>
- <li><p class="first"><strong>Associative array method:</strong></p>
- <blockquote>
- <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>
- <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>
- <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' AND `page1` LIKE '%match%' ESCAPE '!' AND `page2` LIKE '%match%' ESCAPE '!'</span>
- </pre></div>
- </div>
- </div></blockquote>
- </li>
- </ol>
- <p><strong>$this->db->or_like()</strong></p>
- <p>This method is identical to the one above, except that multiple
- instances are joined by OR:</p>
- <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>
- <span class="c1">// WHERE `title` LIKE '%match%' ESCAPE '!' OR `body` LIKE '%match%' ESCAPE '!'</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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>
- </div>
- <p><strong>$this->db->not_like()</strong></p>
- <p>This method is identical to <code class="docutils literal"><span class="pre">like()</span></code>, except that it generates
- NOT LIKE statements:</p>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->or_not_like()</strong></p>
- <p>This method is identical to <code class="docutils literal"><span class="pre">not_like()</span></code>, except that multiple
- instances are joined by OR:</p>
- <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_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>
- <span class="c1">// WHERE `title` LIKE '%match% OR `body` NOT LIKE '%match%' ESCAPE '!'</span>
- </pre></div>
- </div>
- <p><strong>$this->db->group_by()</strong></p>
- <p>Permits you to write the GROUP BY portion of your query:</p>
- <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>
- </pre></div>
- </div>
- <p>You can also pass an array of multiple values as well:</p>
- <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>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">group_by() was formerly known as groupby(), which has been
- removed.</p>
- </div>
- <p><strong>$this->db->distinct()</strong></p>
- <p>Adds the “DISTINCT” keyword to a query</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->having()</strong></p>
- <p>Permits you to write the HAVING portion of your query. There are 2
- possible syntaxes, 1 argument or 2:</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p>You can also pass an array of multiple values as well:</p>
- <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>
- <span class="c1">// Produces: HAVING title = 'My Title', id < 45</span>
- </pre></div>
- </div>
- <p>If you are using a database that CodeIgniter escapes queries for, you
- can prevent escaping content by passing an optional third argument, and
- setting it to FALSE.</p>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->or_having()</strong></p>
- <p>Identical to having(), only separates multiple clauses with “OR”.</p>
- </div>
- <div class="section" id="ordering-results">
- <h2><a class="toc-backref" href="#id4">Ordering results</a><a class="headerlink" href="#ordering-results" title="Permalink to this headline">¶</a></h2>
- <p><strong>$this->db->order_by()</strong></p>
- <p>Lets you set an ORDER BY clause.</p>
- <p>The first parameter contains the name of the column you would like to order by.</p>
- <p>The second parameter lets you set the direction of the result.
- Options are <strong>ASC</strong>, <strong>DESC</strong> AND <strong>RANDOM</strong>.</p>
- <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>
- <span class="c1">// Produces: ORDER BY `title` DESC</span>
- </pre></div>
- </div>
- <p>You can also pass your own string in the first parameter:</p>
- <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>
- <span class="c1">// Produces: ORDER BY `title` DESC, `name` ASC</span>
- </pre></div>
- </div>
- <p>Or multiple function calls can be made if you need multiple fields.</p>
- <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>
- <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>
- <span class="c1">// Produces: ORDER BY `title` DESC, `name` ASC</span>
- </pre></div>
- </div>
- <p>If you choose the <strong>RANDOM</strong> direction option, then the first parameters will
- be ignored, unless you specify a numeric seed value.</p>
- <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>
- <span class="c1">// Produces: ORDER BY RAND()</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="mi">42</span><span class="p">,</span> <span class="s1">'RANDOM'</span><span class="p">);</span>
- <span class="c1">// Produces: ORDER BY RAND(42)</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">order_by() was formerly known as orderby(), which has been
- removed.</p>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">Random ordering is not currently supported in Oracle and
- will default to ASC instead.</p>
- </div>
- </div>
- <div class="section" id="limiting-or-counting-results">
- <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>
- <p><strong>$this->db->limit()</strong></p>
- <p>Lets you limit the number of rows you would like returned by the query:</p>
- <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>
- </pre></div>
- </div>
- <p>The second parameter lets you set a result offset.</p>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->count_all_results()</strong></p>
- <p>Permits you to determine the number of rows in a particular Active
- Record query. Queries will accept Query Builder restrictors such as
- <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>
- <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>
- <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">from</span><span class="p">(</span><span class="s1">'my_table'</span><span class="p">);</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="c1">// Produces an integer, like 17</span>
- </pre></div>
- </div>
- <p>However, this method also resets any field values that you may have passed
- 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
- second parameter:</p>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->count_all()</strong></p>
- <p>Permits you to determine the number of rows in a particular table.
- Submit the table name in the first parameter. Example:</p>
- <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>
- </pre></div>
- </div>
- </div>
- <div class="section" id="query-grouping">
- <h2><a class="toc-backref" href="#id6">Query grouping</a><a class="headerlink" href="#query-grouping" title="Permalink to this headline">¶</a></h2>
- <p>Query grouping allows you to create groups of WHERE clauses by enclosing them in parentheses. This will allow
- you to create queries with complex WHERE clauses. Nested groups are supported. Example:</p>
- <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>
- <span class="o">-></span><span class="na">group_start</span><span class="p">()</span>
- <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>
- <span class="o">-></span><span class="na">or_group_start</span><span class="p">()</span>
- <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>
- <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>
- <span class="o">-></span><span class="na">group_end</span><span class="p">()</span>
- <span class="o">-></span><span class="na">group_end</span><span class="p">()</span>
- <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>
- <span class="o">-></span><span class="na">get</span><span class="p">();</span>
- <span class="c1">// Generates:</span>
- <span class="c1">// SELECT * FROM (`my_table`) WHERE ( `a` = 'a' OR ( `b` = 'b' AND `c` = 'c' ) ) AND `d` = 'd'</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">groups need to be balanced, make sure every group_start() is matched by a group_end().</p>
- </div>
- <p><strong>$this->db->group_start()</strong></p>
- <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query.</p>
- <p><strong>$this->db->or_group_start()</strong></p>
- <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘OR’.</p>
- <p><strong>$this->db->not_group_start()</strong></p>
- <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘NOT’.</p>
- <p><strong>$this->db->or_not_group_start()</strong></p>
- <p>Starts a new group by adding an opening parenthesis to the WHERE clause of the query, prefixing it with ‘OR NOT’.</p>
- <p><strong>$this->db->group_end()</strong></p>
- <p>Ends the current group by adding an closing parenthesis to the WHERE clause of the query.</p>
- </div>
- <div class="section" id="inserting-data">
- <h2><a class="toc-backref" href="#id7">Inserting Data</a><a class="headerlink" href="#inserting-data" title="Permalink to this headline">¶</a></h2>
- <p><strong>$this->db->insert()</strong></p>
- <p>Generates an insert string based on the data you supply, and runs the
- query. You can either pass an <strong>array</strong> or an <strong>object</strong> to the
- function. Here is an example using an array:</p>
- <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>
- <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span>
- <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</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">insert</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="c1">// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')</span>
- </pre></div>
- </div>
- <p>The first parameter will contain the table name, the second is an
- associative array of values.</p>
- <p>Here is an example using an object:</p>
- <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span>
- <span class="cm">class Myclass {</span>
- <span class="cm"> public $title = 'My Title';</span>
- <span class="cm"> public $content = 'My Content';</span>
- <span class="cm"> public $date = 'My Date';</span>
- <span class="cm">}</span>
- <span class="cm">*/</span>
- <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</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">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">,</span> <span class="nv">$object</span><span class="p">);</span>
- <span class="c1">// Produces: INSERT INTO mytable (title, content, date) VALUES ('My Title', 'My Content', 'My Date')</span>
- </pre></div>
- </div>
- <p>The first parameter will contain the table name, the second is an
- object.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values are escaped automatically producing safer queries.</p>
- </div>
- <p><strong>$this->db->get_compiled_insert()</strong></p>
- <p>Compiles the insertion query just like $this->db->insert() but does not
- <em>run</em> the query. This method simply returns the SQL query as a string.</p>
- <p>Example:</p>
- <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>
- <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span>
- <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</span>
- <span class="p">);</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">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>
- <span class="k">echo</span> <span class="nv">$sql</span><span class="p">;</span>
- <span class="c1">// Produces string: INSERT INTO mytable (`title`, `name`, `date`) VALUES ('My title', 'My name', 'My date')</span>
- </pre></div>
- </div>
- <p>The second parameter enables you to set whether or not the query builder query
- will be reset (by default it will be–just like $this->db->insert()):</p>
- <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>
- <span class="c1">// Produces string: INSERT INTO mytable (`title`) VALUES ('My Title')</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">'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>
- <span class="c1">// Produces string: INSERT INTO mytable (`title`, `content`) VALUES ('My Title', 'My Content')</span>
- </pre></div>
- </div>
- <p>The key thing to notice in the above example is that the second query did not
- utilize <cite>$this->db->from()</cite> nor did it pass a table name into the first
- parameter. The reason this worked is because the query has not been executed
- using <cite>$this->db->insert()</cite> which resets values or reset directly using
- <cite>$this->db->reset_query()</cite>.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">This method doesn’t work for batched inserts.</p>
- </div>
- <p><strong>$this->db->insert_batch()</strong></p>
- <p>Generates an insert string based on the data you supply, and runs the
- query. You can either pass an <strong>array</strong> or an <strong>object</strong> to the
- function. Here is an example using an array:</p>
- <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>
- <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">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</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">'Another title'</span><span class="p">,</span>
- <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'Another Name'</span><span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'Another date'</span>
- <span class="p">)</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">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>
- <span class="c1">// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')</span>
- </pre></div>
- </div>
- <p>The first parameter will contain the table name, the second is an
- associative array of values.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values are escaped automatically producing safer queries.</p>
- </div>
- </div>
- <div class="section" id="updating-data">
- <h2><a class="toc-backref" href="#id8">Updating Data</a><a class="headerlink" href="#updating-data" title="Permalink to this headline">¶</a></h2>
- <p><strong>$this->db->replace()</strong></p>
- <p>This method executes a REPLACE statement, which is basically the SQL
- standard for (optional) DELETE + INSERT, using <em>PRIMARY</em> and <em>UNIQUE</em>
- keys as the determining factor.
- In our case, it will save you from the need to implement complex
- 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>,
- <code class="docutils literal"><span class="pre">delete()</span></code> and <code class="docutils literal"><span class="pre">insert()</span></code> calls.</p>
- <p>Example:</p>
- <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>
- <span class="s1">'title'</span> <span class="o">=></span> <span class="s1">'My title'</span><span class="p">,</span>
- <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'My Name'</span><span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date'</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">replace</span><span class="p">(</span><span class="s1">'table'</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span>
- <span class="c1">// Executes: REPLACE INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')</span>
- </pre></div>
- </div>
- <p>In the above example, if we assume that the <em>title</em> field is our primary
- key, then if a row containing ‘My title’ as the <em>title</em> value, that row
- will be deleted with our new row data replacing it.</p>
- <p>Usage of the <code class="docutils literal"><span class="pre">set()</span></code> method is also allowed and all fields are
- automatically escaped, just like with <code class="docutils literal"><span class="pre">insert()</span></code>.</p>
- <p><strong>$this->db->set()</strong></p>
- <p>This function enables you to set values for inserts or updates.</p>
- <p><strong>It can be used instead of passing a data array directly to the insert
- or update functions:</strong></p>
- <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>
- <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>
- </pre></div>
- </div>
- <p>If you use multiple function called they will be assembled properly
- based on whether you are doing an insert or an update:</p>
- <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>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p><strong>set()</strong> will also accept an optional third parameter (<code class="docutils literal"><span class="pre">$escape</span></code>), that
- will prevent data from being escaped if set to FALSE. To illustrate the
- difference, here is <code class="docutils literal"><span class="pre">set()</span></code> used both with and without the escape
- parameter.</p>
- <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>
- <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>
- <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>
- <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="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>
- <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>
- </pre></div>
- </div>
- <p>You can also pass an associative array to this function:</p>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p>Or an object:</p>
- <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span>
- <span class="cm">class Myclass {</span>
- <span class="cm"> public $title = 'My Title';</span>
- <span class="cm"> public $content = 'My Content';</span>
- <span class="cm"> public $date = 'My Date';</span>
- <span class="cm">}</span>
- <span class="cm">*/</span>
- <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</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">set</span><span class="p">(</span><span class="nv">$object</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">insert</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span>
- </pre></div>
- </div>
- <p><strong>$this->db->update()</strong></p>
- <p>Generates an update string and runs the query based on the data you
- supply. You can pass an <strong>array</strong> or an <strong>object</strong> to the function. Here
- is an example using an array:</p>
- <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>
- <span class="s1">'title'</span> <span class="o">=></span> <span class="nv">$title</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">'date'</span> <span class="o">=></span> <span class="nv">$date</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">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="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="c1">// Produces:</span>
- <span class="c1">//</span>
- <span class="c1">// UPDATE mytable</span>
- <span class="c1">// SET title = '{$title}', name = '{$name}', date = '{$date}'</span>
- <span class="c1">// WHERE id = $id</span>
- </pre></div>
- </div>
- <p>Or you can supply an object:</p>
- <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="cm">/*</span>
- <span class="cm">class Myclass {</span>
- <span class="cm"> public $title = 'My Title';</span>
- <span class="cm"> public $content = 'My Content';</span>
- <span class="cm"> public $date = 'My Date';</span>
- <span class="cm">}</span>
- <span class="cm">*/</span>
- <span class="nv">$object</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Myclass</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">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="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>
- <span class="c1">// Produces:</span>
- <span class="c1">//</span>
- <span class="c1">// UPDATE `mytable`</span>
- <span class="c1">// SET `title` = '{$title}', `name` = '{$name}', `date` = '{$date}'</span>
- <span class="c1">// WHERE id = `$id`</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values are escaped automatically producing safer queries.</p>
- </div>
- <p>You’ll notice the use of the $this->db->where() function, enabling you
- to set the WHERE clause. You can optionally pass this information
- directly into the update function as a string:</p>
- <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>
- </pre></div>
- </div>
- <p>Or as an array:</p>
- <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>
- </pre></div>
- </div>
- <p>You may also use the $this->db->set() function described above when
- performing updates.</p>
- <p><strong>$this->db->update_batch()</strong></p>
- <p>Generates an update string based on the data you supply, and runs the query.
- You can either pass an <strong>array</strong> or an <strong>object</strong> to the function.
- Here is an example using an array:</p>
- <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>
- <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">'name'</span> <span class="o">=></span> <span class="s1">'My Name 2'</span> <span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'My date 2'</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">'Another title'</span> <span class="p">,</span>
- <span class="s1">'name'</span> <span class="o">=></span> <span class="s1">'Another Name 2'</span> <span class="p">,</span>
- <span class="s1">'date'</span> <span class="o">=></span> <span class="s1">'Another date 2'</span>
- <span class="p">)</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">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>
- <span class="c1">// Produces:</span>
- <span class="c1">// UPDATE `mytable` SET `name` = CASE</span>
- <span class="c1">// WHEN `title` = 'My title' THEN 'My Name 2'</span>
- <span class="c1">// WHEN `title` = 'Another title' THEN 'Another Name 2'</span>
- <span class="c1">// ELSE `name` END,</span>
- <span class="c1">// `date` = CASE</span>
- <span class="c1">// WHEN `title` = 'My title' THEN 'My date 2'</span>
- <span class="c1">// WHEN `title` = 'Another title' THEN 'Another date 2'</span>
- <span class="c1">// ELSE `date` END</span>
- <span class="c1">// WHERE `title` IN ('My title','Another title')</span>
- </pre></div>
- </div>
- <p>The first parameter will contain the table name, the second is an associative
- array of values, the third parameter is the where key.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">All values are escaped automatically producing safer queries.</p>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last"><code class="docutils literal"><span class="pre">affected_rows()</span></code> won’t give you proper results with this method,
- due to the very nature of how it works. Instead, <code class="docutils literal"><span class="pre">update_batch()</span></code>
- returns the number of rows affected.</p>
- </div>
- <p><strong>$this->db->get_compiled_update()</strong></p>
- <p>This works exactly the same way as <code class="docutils literal"><span class="pre">$this->db->get_compiled_insert()</span></code> except
- that it produces an UPDATE SQL string instead of an INSERT SQL string.</p>
- <p>For more information view documentation for <cite>$this->db->get_compiled_insert()</cite>.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">This method doesn’t work for batched updates.</p>
- </div>
- </div>
- <div class="section" id="deleting-data">
- <h2><a class="toc-backref" href="#id9">Deleting Data</a><a class="headerlink" href="#deleting-data" title="Permalink to this headline">¶</a></h2>
- <p><strong>$this->db->delete()</strong></p>
- <p>Generates a delete SQL string and runs the query.</p>
- <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>
- </pre></div>
- </div>
- <p>The first parameter is the table name, the second is the where clause.
- You can also use the where() or or_where() functions instead of passing
- the data to the second parameter of the function:</p>
- <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>
- <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="c1">// Produces:</span>
- <span class="c1">// DELETE FROM mytable</span>
- <span class="c1">// WHERE id = $id</span>
- </pre></div>
- </div>
- <p>An array of table names can be passed into delete() if you would like to
- delete data from more than 1 table.</p>
- <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>
- <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>
- <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>
- </pre></div>
- </div>
- <p>If you want to delete all data from a table, you can use the truncate()
- function, or empty_table().</p>
- <p><strong>$this->db->empty_table()</strong></p>
- <p>Generates a delete SQL string and runs the
- query.:</p>
- <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>
- </pre></div>
- </div>
- <p><strong>$this->db->truncate()</strong></p>
- <p>Generates a truncate SQL string and runs the query.</p>
- <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>
- <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="c1">// or</span>
- <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>
- <span class="c1">// Produce:</span>
- <span class="c1">// TRUNCATE mytable</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">If the TRUNCATE command isn’t available, truncate() will
- execute as “DELETE FROM table”.</p>
- </div>
- <p><strong>$this->db->get_compiled_delete()</strong></p>
- <p>This works exactly the same way as <code class="docutils literal"><span class="pre">$this->db->get_compiled_insert()</span></code> except
- that it produces a DELETE SQL string instead of an INSERT SQL string.</p>
- <p>For more information view documentation for $this->db->get_compiled_insert().</p>
- </div>
- <div class="section" id="method-chaining">
- <h2><a class="toc-backref" href="#id10">Method Chaining</a><a class="headerlink" href="#method-chaining" title="Permalink to this headline">¶</a></h2>
- <p>Method chaining allows you to simplify your syntax by connecting
- multiple functions. Consider this example:</p>
- <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>
- <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="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</span><span class="p">(</span><span class="s1">'mytable'</span><span class="p">);</span>
- </pre></div>
- </div>
- </div>
- <div class="section" id="query-builder-caching">
- <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>
- <p>While not “true” caching, Query Builder enables you to save (or “cache”)
- certain parts of your queries for reuse at a later point in your
- script’s execution. Normally, when an Query Builder call is completed,
- all stored information is reset for the next call. With caching, you can
- prevent this reset, and reuse information easily.</p>
- <p>Cached calls are cumulative. If you make 2 cached select() calls, and
- then 2 uncached select() calls, this will result in 4 select() calls.
- There are three Caching functions available:</p>
- <p><strong>$this->db->start_cache()</strong></p>
- <p>This function must be called to begin caching. All Query Builder queries
- of the correct type (see below for supported queries) are stored for
- later use.</p>
- <p><strong>$this->db->stop_cache()</strong></p>
- <p>This function can be called to stop caching.</p>
- <p><strong>$this->db->flush_cache()</strong></p>
- <p>This function deletes all items from the Query Builder cache.</p>
- <div class="section" id="an-example-of-caching">
- <h3>An example of caching<a class="headerlink" href="#an-example-of-caching" title="Permalink to this headline">¶</a></h3>
- <p>Here’s a usage example:</p>
- <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>
- <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>
- <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>
- <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>
- <span class="c1">//Generates: SELECT `field1` FROM (`tablename`)</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">'field2'</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">get</span><span class="p">(</span><span class="s1">'tablename'</span><span class="p">);</span>
- <span class="c1">//Generates: SELECT `field1`, `field2` FROM (`tablename`)</span>
- <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>
- <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>
- <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>
- <span class="c1">//Generates: SELECT `field2` FROM (`tablename`)</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">The following statements can be cached: select, from, join,
- where, like, group_by, having, order_by</p>
- </div>
- </div>
- </div>
- <div class="section" id="resetting-query-builder">
- <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>
- <p><strong>$this->db->reset_query()</strong></p>
- <p>Resetting Query Builder allows you to start fresh with your query without
- executing it first using a method like $this->db->get() or $this->db->insert().
- Just like the methods that execute a query, this will <em>not</em> reset items you’ve
- cached using <a class="reference internal" href="#query-builder-caching">Query Builder Caching</a>.</p>
- <p>This is useful in situations where you are using Query Builder to generate SQL
- (ex. <code class="docutils literal"><span class="pre">$this->db->get_compiled_select()</span></code>) but then choose to, for instance,
- run the query:</p>
- <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>
- <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>
- <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>
- <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>
- <span class="c1">// ...</span>
- <span class="c1">// Do something crazy with the SQL code... like add it to a cron script for</span>
- <span class="c1">// later execution or something...</span>
- <span class="c1">// ...</span>
- <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>
- <span class="c1">// Would execute and return an array of results of the following query:</span>
- <span class="c1">// SELECT field1, field1 from mytable where field3 = 5;</span>
- </pre></div>
- </div>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">Double calls to <code class="docutils literal"><span class="pre">get_compiled_select()</span></code> while you’re using the
- Query Builder Caching functionality and NOT resetting your queries
- will results in the cache being merged twice. That in turn will
- i.e. if you’re caching a <code class="docutils literal"><span class="pre">select()</span></code> - select the same field twice.</p>
- </div>
- </div>
- <div class="section" id="class-reference">
- <h2><a class="toc-backref" href="#id13">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2>
- <dl class="class">
- <dt id="CI_DB_query_builder">
- <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>
- <dd><dl class="method">
- <dt id="CI_DB_query_builder::reset_query">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Resets the current Query Builder state. Useful when you want
- to build a query that can be cancelled under certain conditions.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::start_cache">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Starts the Query Builder cache.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::stop_cache">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Stops the Query Builder cache.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::flush_cache">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Empties the Query Builder cache.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::set_dbprefix">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$prefix</strong> (<em>string</em>) – The new prefix to use</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The DB prefix in use</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Sets the database prefix, without having to reconnect.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::dbprefix">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – The table name to prefix</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The prefixed table name</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Prepends a database prefix, if one exists in configuration.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::count_all_results">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset values for SELECTs</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">int</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates a platform-specific query string that counts
- all records returned by an Query Builder query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – The table to query</li>
- <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li>
- <li><strong>$offset</strong> (<em>int</em>) – The OFFSET clause</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_result</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and runs SELECT statement based on the already
- called Query Builder methods.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get_where">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>mixed</em>) – The table(s) to fetch data from; string or array</li>
- <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li>
- <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li>
- <li><strong>$offset</strong> (<em>int</em>) – The OFFSET clause</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_DB_result</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Same as <code class="docutils literal"><span class="pre">get()</span></code>, but also allows the WHERE to be added directly.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::select">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$select</strong> (<em>string</em>) – The SELECT portion of a query</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a SELECT clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::select_avg">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$select</strong> (<em>string</em>) – Field to compute the average of</li>
- <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a SELECT AVG(field) clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::select_max">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$select</strong> (<em>string</em>) – Field to compute the maximum of</li>
- <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a SELECT MAX(field) clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::select_min">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$select</strong> (<em>string</em>) – Field to compute the minimum of</li>
- <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a SELECT MIN(field) clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::select_sum">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$select</strong> (<em>string</em>) – Field to compute the sum of</li>
- <li><strong>$alias</strong> (<em>string</em>) – Alias for the resulting value name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a SELECT SUM(field) clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::distinct">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$val</strong> (<em>bool</em>) – Desired value of the “distinct” flag</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Sets a flag which tells the query builder to add
- a DISTINCT clause to the SELECT portion of the query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::from">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$from</strong> (<em>mixed</em>) – Table name(s); string or array</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Specifies the FROM clause of a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::join">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name to join</li>
- <li><strong>$cond</strong> (<em>string</em>) – The JOIN ON condition</li>
- <li><strong>$type</strong> (<em>string</em>) – The JOIN type</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a JOIN clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::where">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Name of field to compare, or associative array</li>
- <li><strong>$value</strong> (<em>mixed</em>) – If a single key, compared to this value</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates the WHERE portion of the query.
- Separates multiple calls with ‘AND’.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_where">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Name of field to compare, or associative array</li>
- <li><strong>$value</strong> (<em>mixed</em>) – If a single key, compared to this value</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates the WHERE portion of the query.
- Separates multiple calls with ‘OR’.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_where_in">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>string</em>) – The field to search</li>
- <li><strong>$values</strong> (<em>array</em>) – The values searched on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates a WHERE field IN(‘item’, ‘item’) SQL query,
- joined with ‘OR’ if appropriate.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_where_not_in">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>string</em>) – The field to search</li>
- <li><strong>$values</strong> (<em>array</em>) – The values searched on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates a WHERE field NOT IN(‘item’, ‘item’) SQL query,
- joined with ‘OR’ if appropriate.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::where_in">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>string</em>) – Name of field to examine</li>
- <li><strong>$values</strong> (<em>array</em>) – Array of target values</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates a WHERE field IN(‘item’, ‘item’) SQL query,
- joined with ‘AND’ if appropriate.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::where_not_in">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>string</em>) – Name of field to examine</li>
- <li><strong>$values</strong> (<em>array</em>) – Array of target values</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">DB_query_builder instance</p>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">object</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Generates a WHERE field NOT IN(‘item’, ‘item’) SQL query,
- joined with ‘AND’ if appropriate.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::group_start">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Starts a group expression, using ANDs for the conditions inside it.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_group_start">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Starts a group expression, using ORs for the conditions inside it.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::not_group_start">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Starts a group expression, using AND NOTs for the conditions inside it.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_not_group_start">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_DB_query_builder instance (method chaining)</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_DB_query_builder</td>
- </tr>
- </tbody>
- </table>
- <p>Starts a group expression, using OR NOTs for the conditions inside it.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::group_end">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">DB_query_builder instance</td>
- </tr>
- <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">object</td>
- </tr>
- </tbody>
- </table>
- <p>Ends a group expression.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::like">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$field</strong> (<em>string</em>) – Field name</li>
- <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li>
- <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a LIKE clause to a query, separating multiple calls with AND.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_like">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$field</strong> (<em>string</em>) – Field name</li>
- <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li>
- <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a LIKE clause to a query, separating multiple class with OR.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::not_like">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$field</strong> (<em>string</em>) – Field name</li>
- <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li>
- <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a NOT LIKE clause to a query, separating multiple calls with AND.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_not_like">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$field</strong> (<em>string</em>) – Field name</li>
- <li><strong>$match</strong> (<em>string</em>) – Text portion to match</li>
- <li><strong>$side</strong> (<em>string</em>) – Which side of the expression to put the ‘%’ wildcard on</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a NOT LIKE clause to a query, separating multiple calls with OR.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::having">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Identifier (string) or associative array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Value sought if $key is an identifier</li>
- <li><strong>$escape</strong> (<em>string</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a HAVING clause to a query, separating multiple calls with AND.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::or_having">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Identifier (string) or associative array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Value sought if $key is an identifier</li>
- <li><strong>$escape</strong> (<em>string</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a HAVING clause to a query, separating multiple calls with OR.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::group_by">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$by</strong> (<em>mixed</em>) – Field(s) to group by; string or array</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds a GROUP BY clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::order_by">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$orderby</strong> (<em>string</em>) – Field to order by</li>
- <li><strong>$direction</strong> (<em>string</em>) – The order requested - ASC, DESC or random</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds an ORDER BY clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::limit">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$value</strong> (<em>int</em>) – Number of rows to limit the results to</li>
- <li><strong>$offset</strong> (<em>int</em>) – Number of rows to skip</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds LIMIT and OFFSET clauses to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::offset">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$offset</strong> (<em>int</em>) – Number of rows to skip</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds an OFFSET clause to a query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::set">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Field name, or an array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Adds field/value pairs to be passed later to <code class="docutils literal"><span class="pre">insert()</span></code>,
- <code class="docutils literal"><span class="pre">update()</span></code> or <code class="docutils literal"><span class="pre">replace()</span></code>.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::insert">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes an INSERT statement.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::insert_batch">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$set</strong> (<em>array</em>) – Data to insert</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- <li><strong>$batch_size</strong> (<em>int</em>) – Count of rows to insert at once</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes batch <code class="docutils literal"><span class="pre">INSERT</span></code> statements.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">When more than <code class="docutils literal"><span class="pre">$batch_size</span></code> rows are provided, multiple
- <code class="docutils literal"><span class="pre">INSERT</span></code> queries will be executed, each trying to insert
- up to <code class="docutils literal"><span class="pre">$batch_size</span></code> rows.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::set_insert_batch">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Field name or an array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::update">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li>
- <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li>
- <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes an UPDATE statement.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::update_batch">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$set</strong> (<em>array</em>) – Field name, or an associative array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Field value, if $set is a single field</li>
- <li><strong>$batch_size</strong> (<em>int</em>) – Count of conditions to group in a single query</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes batch <code class="docutils literal"><span class="pre">UPDATE</span></code> statements.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">When more than <code class="docutils literal"><span class="pre">$batch_size</span></code> field/value pairs are provided,
- multiple queries will be executed, each handling up to
- <code class="docutils literal"><span class="pre">$batch_size</span></code> field/value pairs.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::set_update_batch">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$key</strong> (<em>mixed</em>) – Field name or an array of field/value pairs</li>
- <li><strong>$value</strong> (<em>string</em>) – Field value, if $key is a single field</li>
- <li><strong>$escape</strong> (<em>bool</em>) – Whether to escape values and identifiers</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- </tbody>
- </table>
- <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>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::replace">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$set</strong> (<em>array</em>) – An associative array of field/value pairs</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes a REPLACE statement.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::delete">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>mixed</em>) – The table(s) to delete from; string or array</li>
- <li><strong>$where</strong> (<em>string</em>) – The WHERE clause</li>
- <li><strong>$limit</strong> (<em>int</em>) – The LIMIT clause</li>
- <li><strong>$reset_data</strong> (<em>bool</em>) – TRUE to reset the query “write” clause</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles and executes a DELETE query.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::truncate">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Executes a TRUNCATE statement on a table.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">If the database platform in use doesn’t support TRUNCATE,
- a DELETE statement will be used instead.</p>
- </div>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::empty_table">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Deletes all records from a table via a DELETE statement.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get_compiled_select">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles a SELECT statement and returns it as a string.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get_compiled_insert">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles an INSERT statement and returns it as a string.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get_compiled_update">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles an UPDATE statement and returns it as a string.</p>
- </dd></dl>
- <dl class="method">
- <dt id="CI_DB_query_builder::get_compiled_delete">
- <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>
- <dd><table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
- <li><strong>$table</strong> (<em>string</em>) – Table name</li>
- <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset the current QB values or not</li>
- </ul>
- </td>
- </tr>
- <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>
- </td>
- </tr>
- <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
- </td>
- </tr>
- </tbody>
- </table>
- <p>Compiles a DELETE statement and returns it as a string.</p>
- </dd></dl>
- </dd></dl>
- </div>
- </div>
- </div>
- <footer>
-
- <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
-
- <a href="transactions.html" class="btn btn-neutral float-right" title="Transactions">Next <span class="fa fa-arrow-circle-right"></span></a>
-
-
- <a href="helpers.html" class="btn btn-neutral" title="Query Helper Methods"><span class="fa fa-arrow-circle-left"></span> Previous</a>
-
- </div>
-
- <hr/>
- <div role="contentinfo">
- <p>
- © Copyright 2014 - 2019, British Columbia Institute of Technology.
- Last updated on Sep 19, 2019.
- </p>
- </div>
- Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
-
- </footer>
- </div>
- </div>
- </section>
- </div>
-
-
- <script type="text/javascript">
- var DOCUMENTATION_OPTIONS = {
- URL_ROOT:'../',
- VERSION:'3.1.11',
- COLLAPSE_INDEX:false,
- FILE_SUFFIX:'.html',
- HAS_SOURCE: false
- };
- </script>
- <script type="text/javascript" src="../_static/jquery.js"></script>
- <script type="text/javascript" src="../_static/underscore.js"></script>
- <script type="text/javascript" src="../_static/doctools.js"></script>
-
-
-
- <script type="text/javascript" src="../_static/js/theme.js"></script>
-
-
-
- <script type="text/javascript">
- jQuery(function () {
- SphinxRtdTheme.StickyNav.enable();
- });
- </script>
-
- </body>
- </html>
|