MySqlConnection.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Illuminate\Database;
  3. use PDO;
  4. use Illuminate\Database\Schema\MySqlBuilder;
  5. use Illuminate\Database\Query\Processors\MySqlProcessor;
  6. use Doctrine\DBAL\Driver\PDOMySql\Driver as DoctrineDriver;
  7. use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
  8. use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
  9. class MySqlConnection extends Connection
  10. {
  11. /**
  12. * Get the default query grammar instance.
  13. *
  14. * @return \Illuminate\Database\Query\Grammars\MySqlGrammar
  15. */
  16. protected function getDefaultQueryGrammar()
  17. {
  18. return $this->withTablePrefix(new QueryGrammar);
  19. }
  20. /**
  21. * Get a schema builder instance for the connection.
  22. *
  23. * @return \Illuminate\Database\Schema\MySqlBuilder
  24. */
  25. public function getSchemaBuilder()
  26. {
  27. if (is_null($this->schemaGrammar)) {
  28. $this->useDefaultSchemaGrammar();
  29. }
  30. return new MySqlBuilder($this);
  31. }
  32. /**
  33. * Get the default schema grammar instance.
  34. *
  35. * @return \Illuminate\Database\Schema\Grammars\MySqlGrammar
  36. */
  37. protected function getDefaultSchemaGrammar()
  38. {
  39. return $this->withTablePrefix(new SchemaGrammar);
  40. }
  41. /**
  42. * Get the default post processor instance.
  43. *
  44. * @return \Illuminate\Database\Query\Processors\MySqlProcessor
  45. */
  46. protected function getDefaultPostProcessor()
  47. {
  48. return new MySqlProcessor;
  49. }
  50. /**
  51. * Get the Doctrine DBAL driver.
  52. *
  53. * @return \Doctrine\DBAL\Driver\PDOMySql\Driver
  54. */
  55. protected function getDoctrineDriver()
  56. {
  57. return new DoctrineDriver;
  58. }
  59. /**
  60. * Bind values to their parameters in the given statement.
  61. *
  62. * @param \PDOStatement $statement
  63. * @param array $bindings
  64. * @return void
  65. */
  66. public function bindValues($statement, $bindings)
  67. {
  68. foreach ($bindings as $key => $value) {
  69. $statement->bindValue(
  70. is_string($key) ? $key : $key + 1, $value,
  71. is_int($value) || is_float($value) ? PDO::PARAM_INT : PDO::PARAM_STR
  72. );
  73. }
  74. }
  75. }