Advertisement
ariesm_

eloq

Apr 1st, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.98 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. use Illuminate\Database\Capsule\Manager as Capsule;
  4. /*
  5. | -------------------------------------------------------------------
  6. | DATABASE CONNECTIVITY SETTINGS
  7. | -------------------------------------------------------------------
  8. | This file will contain the settings needed to access your database.
  9. |
  10. | For complete instructions please consult the 'Database Connection'
  11. | page of the User Guide.
  12. |
  13. | -------------------------------------------------------------------
  14. | EXPLANATION OF VARIABLES
  15. | -------------------------------------------------------------------
  16. |
  17. |   ['dsn']      The full DSN string describe a connection to the database.
  18. |   ['hostname'] The hostname of your database server.
  19. |   ['username'] The username used to connect to the database
  20. |   ['password'] The password used to connect to the database
  21. |   ['database'] The name of the database you want to connect to
  22. |   ['dbdriver'] The database driver. e.g.: mysqli.
  23. |           Currently supported:
  24. |                cubrid, ibase, mssql, mysql, mysqli, oci8,
  25. |                odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
  26. |   ['dbprefix'] You can add an optional prefix, which will be added
  27. |                to the table name when using the  Query Builder class
  28. |   ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
  29. |   ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
  30. |   ['cache_on'] TRUE/FALSE - Enables/disables query caching
  31. |   ['cachedir'] The path to the folder where cache files should be stored
  32. |   ['char_set'] The character set used in communicating with the database
  33. |   ['dbcollat'] The character collation used in communicating with the database
  34. |                NOTE: For MySQL and MySQLi databases, this setting is only used
  35. |                as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
  36. |                (and in table creation queries made with DB Forge).
  37. |                There is an incompatibility in PHP with mysql_real_escape_string() which
  38. |                can make your site vulnerable to SQL injection if you are using a
  39. |                multi-byte character set and are running versions lower than these.
  40. |                Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
  41. |   ['swap_pre'] A default table prefix that should be swapped with the dbprefix
  42. |   ['encrypt']  Whether or not to use an encrypted connection.
  43. |   ['compress'] Whether or not to use client compression (MySQL only)
  44. |   ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
  45. |                           - good for ensuring strict SQL while developing
  46. |   ['failover'] array - A array with 0 or more data for connections if the main should fail.
  47. |   ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
  48. |               NOTE: Disabling this will also effectively disable both
  49. |               $this->db->last_query() and profiling of DB queries.
  50. |               When you run a query, with this setting set to TRUE (default),
  51. |               CodeIgniter will store the SQL statement for debugging purposes.
  52. |               However, this may cause high memory usage, especially if you run
  53. |               a lot of SQL queries ... disable this to avoid that problem.
  54. |
  55. | The $active_group variable lets you choose which connection group to
  56. | make active.  By default there is only one group (the 'default' group).
  57. |
  58. | The $query_builder variables lets you determine whether or not to load
  59. | the query builder class.
  60. */
  61.  
  62. $active_group = 'default';
  63. $query_builder = TRUE;
  64.  
  65. $db['default'] = array(
  66.     'dsn'   => '',
  67.     'hostname' => 'localhost',
  68.     'username' => 'root',
  69.     'password' => '123457',
  70.     'database' => 'citiga',
  71.     'dbdriver' => 'mysqli',
  72.     'dbprefix' => '',
  73.     'pconnect' => FALSE,
  74.     'db_debug' => TRUE,
  75.     'cache_on' => FALSE,
  76.     'cachedir' => '',
  77.     'char_set' => 'utf8',
  78.     'dbcollat' => 'utf8_general_ci',
  79.     'swap_pre' => '',
  80.     'encrypt' => FALSE,
  81.     'compress' => FALSE,
  82.     'stricton' => FALSE,
  83.     'failover' => array(),
  84.     'save_queries' => TRUE
  85. );
  86.  
  87. $capsule = new Capsule;
  88.  
  89. $capsule->addConnection(array(
  90. 'driver' => in_array($db['default']['dbdriver'], array('mysql', 'mysqli')) ? 'mysql' : $db['default']['dbdriver'],
  91. 'host' => $db['default']['hostname'],
  92. 'database' => $db['default']['database'],
  93. 'username' => $db['default']['username'],
  94. 'password' => $db['default']['password'],
  95. 'charset' => 'utf8',
  96. 'collation' => 'utf8_unicode_ci',
  97. 'prefix' => $db['default']['dbprefix'],
  98. ));
  99.  
  100. $capsule->setAsGlobal();
  101. $capsule->bootEloquent();
  102. $events = new Illuminate\Events\Dispatcher;
  103. $events->listen('illuminate.query', function($query, $bindings, $time, $name)
  104. {
  105. // Format binding data for sql insertion
  106. foreach ($bindings as $i => $binding)
  107. {
  108. if ($binding instanceof \DateTime)
  109. {
  110. $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
  111. }
  112. else if (is_string($binding))
  113. {
  114. $bindings[$i] = "'$binding'";
  115. }
  116. }
  117. // Insert bindings into query
  118. $query = str_replace(array('%', '?'), array('%%', '%s'), $query);
  119. $query = vsprintf($query, $bindings);
  120. // Add it into CodeIgniter
  121. $db =& get_instance()->db;
  122. $db->query_times[] = $time;
  123. $db->queries[] = $query;
  124. });
  125.  
  126. $capsule->setEventDispatcher($events);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement