| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714 |
- <!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.6 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.6 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’ 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">'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
- utlize <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 - 2017, British Columbia Institute of Technology.
- Last updated on Sep 25, 2017.
- </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.6',
- 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>
|