MySqlConnection.php 2.0 KB

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