PdoMysql.php 1020 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * MINZ - Copyright 2011 Marien Fressinaud
  5. * Sous licence AGPL3 <http://www.gnu.org/licenses/>
  6. */
  7. class Minz_PdoMysql extends Minz_Pdo {
  8. /**
  9. * @param array<int,int|string|bool>|null $options
  10. * @throws PDOException
  11. */
  12. public function __construct(string $dsn, ?string $username = null, ?string $passwd = null, ?array $options = null) {
  13. parent::__construct($dsn, $username, $passwd, $options);
  14. if (class_exists('Pdo\Mysql')) {
  15. $this->setAttribute(Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, false); // @phpstan-ignore argument.type
  16. } else {
  17. $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); // PHP < 8.4
  18. }
  19. }
  20. #[\Override]
  21. public function dbType(): string {
  22. return 'mysql';
  23. }
  24. /**
  25. * @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
  26. */
  27. #[\Override]
  28. public function lastInsertId(?string $name = null): string|false {
  29. return parent::lastInsertId(); //We discard the name, only used by PostgreSQL
  30. }
  31. }