CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * MySQLi layer for DBO
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs.model.datasources.dbo
 20:  * @since         CakePHP(tm) v 1.1.4.2974
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: App::import('Core', 'DboMysql');
 27: /**
 28:  * MySQLi DBO driver object
 29:  *
 30:  * Provides connection and SQL generation for MySQL RDMS using PHP's MySQLi Interface
 31:  *
 32:  * @package       cake
 33:  * @subpackage    cake.cake.libs.model.datasources.dbo
 34:  */
 35: class DboMysqli extends DboMysqlBase {
 36: /**
 37:  * Enter description here...
 38:  *
 39:  * @var unknown_type
 40:  */
 41:     var $description = "Mysqli DBO Driver";
 42: /**
 43:  * Base configuration settings for Mysqli driver
 44:  *
 45:  * @var array
 46:  */
 47:     var $_baseConfig = array(
 48:         'persistent' => true,
 49:         'host' => 'localhost',
 50:         'login' => 'root',
 51:         'password' => '',
 52:         'database' => 'cake',
 53:         'port' => '3306',
 54:         'connect' => 'mysqli_connect'
 55:     );
 56: /**
 57:  * Connects to the database using options in the given configuration array.
 58:  *
 59:  * @return boolean True if the database could be connected, else false
 60:  */
 61:     function connect() {
 62:         $config = $this->config;
 63:         $this->connected = false;
 64: 
 65:         if (is_numeric($config['port'])) {
 66:             $config['socket'] = null;
 67:         } else {
 68:             $config['socket'] = $config['port'];
 69:             $config['port'] = null;
 70:         }
 71: 
 72:         $this->connection = mysqli_connect($config['host'], $config['login'], $config['password'], $config['database'], $config['port'], $config['socket']);
 73: 
 74:         if ($this->connection !== false) {
 75:             $this->connected = true;
 76:         }
 77:         
 78:         $this->_useAlias = (bool)version_compare(mysqli_get_server_info($this->connection), "4.1", ">=");
 79:         
 80:         if (!empty($config['encoding'])) {
 81:             $this->setEncoding($config['encoding']);
 82:         }
 83:         return $this->connected;
 84:     }
 85: /**
 86:  * Check that MySQLi is installed/enabled
 87:  *
 88:  * @return boolean
 89:  **/
 90:     function enabled() {
 91:         return extension_loaded('mysqli');
 92:     }
 93: /**
 94:  * Disconnects from database.
 95:  *
 96:  * @return boolean True if the database could be disconnected, else false
 97:  */
 98:     function disconnect() {
 99:         if (isset($this->results) && is_resource($this->results)) {
100:             mysqli_free_result($this->results);
101:         }
102:         $this->connected = !@mysqli_close($this->connection);
103:         return !$this->connected;
104:     }
105: /**
106:  * Executes given SQL statement.
107:  *
108:  * @param string $sql SQL statement
109:  * @return resource Result resource identifier
110:  * @access protected
111:  */
112:     function _execute($sql) {
113:         if (preg_match('/^\s*call/i', $sql)) {
114:             return $this->_executeProcedure($sql);
115:         }
116:         return mysqli_query($this->connection, $sql);
117:     }
118: /**
119:  * Executes given SQL statement (procedure call).
120:  *
121:  * @param string $sql SQL statement (procedure call)
122:  * @return resource Result resource identifier for first recordset
123:  * @access protected
124:  */
125:     function _executeProcedure($sql) {
126:         $answer = mysqli_multi_query($this->connection, $sql);
127: 
128:         $firstResult = mysqli_store_result($this->connection);
129: 
130:         if (mysqli_more_results($this->connection)) {
131:             while ($lastResult = mysqli_next_result($this->connection));
132:         }
133:         return $firstResult;
134:     }
135: /**
136:  * Returns an array of sources (tables) in the database.
137:  *
138:  * @return array Array of tablenames in the database
139:  */
140:     function listSources() {
141:         $cache = parent::listSources();
142:         if ($cache != null) {
143:             return $cache;
144:         }
145:         $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';');
146: 
147:         if (!$result) {
148:             return array();
149:         }
150: 
151:         $tables = array();
152: 
153:         while ($line = mysqli_fetch_array($result)) {
154:             $tables[] = $line[0];
155:         }
156:         parent::listSources($tables);
157:         return $tables;
158:     }
159: /**
160:  * Returns a quoted and escaped string of $data for use in an SQL statement.
161:  *
162:  * @param string $data String to be prepared for use in an SQL statement
163:  * @param string $column The column into which this data will be inserted
164:  * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided
165:  * @return string Quoted and escaped data
166:  */
167:     function value($data, $column = null, $safe = false) {
168:         $parent = parent::value($data, $column, $safe);
169: 
170:         if ($parent != null) {
171:             return $parent;
172:         }
173:         if ($data === null || (is_array($data) && empty($data))) {
174:             return 'NULL';
175:         }
176:         if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
177:             return "''";
178:         }
179:         if (empty($column)) {
180:             $column = $this->introspectType($data);
181:         }
182: 
183:         switch ($column) {
184:             case 'boolean':
185:                 return $this->boolean((bool)$data);
186:             break;
187:             case 'integer' :
188:             case 'float' :
189:             case null :
190:                 if ($data === '') {
191:                     return 'NULL';
192:                 }
193:                 if ((is_int($data) || is_float($data) || $data === '0') || (
194:                     is_numeric($data) && strpos($data, ',') === false &&
195:                     $data[0] != '0' && strpos($data, 'e') === false)) {
196:                         return $data;
197:                     }
198:             default:
199:                 $data = "'" . mysqli_real_escape_string($this->connection, $data) . "'";
200:             break;
201:         }
202: 
203:         return $data;
204:     }
205: /**
206:  * Returns a formatted error message from previous database operation.
207:  *
208:  * @return string Error message with error number
209:  */
210:     function lastError() {
211:         if (mysqli_errno($this->connection)) {
212:             return mysqli_errno($this->connection).': '.mysqli_error($this->connection);
213:         }
214:         return null;
215:     }
216: /**
217:  * Returns number of affected rows in previous database operation. If no previous operation exists,
218:  * this returns false.
219:  *
220:  * @return integer Number of affected rows
221:  */
222:     function lastAffected() {
223:         if ($this->_result) {
224:             return mysqli_affected_rows($this->connection);
225:         }
226:         return null;
227:     }
228: /**
229:  * Returns number of rows in previous resultset. If no previous resultset exists,
230:  * this returns false.
231:  *
232:  * @return integer Number of rows in resultset
233:  */
234:     function lastNumRows() {
235:         if ($this->hasResult()) {
236:             return mysqli_num_rows($this->_result);
237:         }
238:         return null;
239:     }
240: /**
241:  * Returns the ID generated from the previous INSERT operation.
242:  *
243:  * @param unknown_type $source
244:  * @return in
245:  */
246:     function lastInsertId($source = null) {
247:         $id = $this->fetchRow('SELECT LAST_INSERT_ID() AS insertID', false);
248:         if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0]['insertID'])) {
249:             return $id[0]['insertID'];
250:         }
251:         return null;
252:     }
253: /**
254:  * Enter description here...
255:  *
256:  * @param unknown_type $results
257:  */
258:     function resultSet(&$results) {
259:         if (isset($this->results) && is_resource($this->results) && $this->results != $results) {
260:             mysqli_free_result($this->results);
261:         }
262:         $this->results =& $results;
263:         $this->map = array();
264:         $numFields = mysqli_num_fields($results);
265:         $index = 0;
266:         $j = 0;
267:         while ($j < $numFields) {
268:             $column = mysqli_fetch_field_direct($results, $j);
269:             if (!empty($column->table)) {
270:                 $this->map[$index++] = array($column->table, $column->name);
271:             } else {
272:                 $this->map[$index++] = array(0, $column->name);
273:             }
274:             $j++;
275:         }
276:     }
277: /**
278:  * Fetches the next row from the current result set
279:  *
280:  * @return unknown
281:  */
282:     function fetchResult() {
283:         if ($row = mysqli_fetch_row($this->results)) {
284:             $resultRow = array();
285:             $i = 0;
286:             foreach ($row as $index => $field) {
287:                 $table = $column = null;
288:                 if (count($this->map[$index]) == 2) {
289:                     list($table, $column) = $this->map[$index];
290:                 }
291:                 $resultRow[$table][$column] = $row[$index];
292:                 $i++;
293:             }
294:             return $resultRow;
295:         }
296:         return false;
297:     }
298: /**
299:  * Gets the database encoding
300:  *
301:  * @return string The database encoding
302:  */
303:     function getEncoding() {
304:         return mysqli_client_encoding($this->connection);
305:     }
306: /**
307:  * Checks if the result is valid
308:  *
309:  * @return boolean True if the result is valid, else false
310:  */
311:     function hasResult() {
312:         return is_object($this->_result);
313:     }
314: }
315: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs