<?php
declare(strict_types=1);

/**
 * MINZ - Copyright 2011 Marien Fressinaud
 * Sous licence AGPL3 <https://www.gnu.org/licenses/>
 */

class Minz_PdoMysql extends Minz_Pdo {
	/**
	 * @param array<int,int|string|bool>|null $options
	 * @throws PDOException
	 */
	public function __construct(string $dsn, ?string $username = null, ?string $passwd = null, ?array $options = null) {
		parent::__construct($dsn, $username, $passwd, $options);
		if (class_exists('Pdo\Mysql')) {
			assert(is_int(Pdo\Mysql::ATTR_USE_BUFFERED_QUERY));	// For PHPStan with PHP 8.4+
			$this->setAttribute(Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, false);
		} else {
			$this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);	// PHP < 8.4
		}
	}

	#[\Override]
	public function dbType(): string {
		return 'mysql';
	}

	/**
	 * @throws PDOException if the attribute `PDO::ATTR_ERRMODE` is set to `PDO::ERRMODE_EXCEPTION`
	 */
	#[\Override]
	public function lastInsertId(?string $name = null): string|false {
		return parent::lastInsertId();	//We discard the name, only used by PostgreSQL
	}
}
