Gets the name of the correct database driver to use. As a side effect,
sets the platform.
public getDriver ( (return-by-ref) &$description ) : -3 | ||
$description | (return-by-ref) | |
Результат | -3 | class name of the driver eg. Postgres84 |
/** * @return null */ public function setUp() { $this->runDbStartupTask(); $connector = DbRegistry::getConnector('af-tester'); $this->conn = $connector->getConnection(); $this->conn->connect(); $driver = $this->conn->getDriver(); $this->stmtDriver = $driver->stmt_init(); $this->stmt = new PreparedStmt($this->stmtDriver); }
/** * @return null */ public function testInitialStatus() { $this->assertTrue($this->conn->isDriver()); $this->assertInstanceOf('mysqli', $this->conn->getDriver()); $this->assertEquals('initialized', $this->conn->getStatus()); $this->assertFalse($this->conn->isError()); $this->assertFalse($this->conn->isConnected()); $this->assertEquals(0, $this->conn->getErrorCode()); $this->assertNull($this->conn->getErrorText()); }
/** * @param string SQL command or table or view name, as data source * @param Connection connection */ public function __construct($sql, Connection $connection) { if (strpbrk($sql, " \t\r\n") === FALSE) { $this->sql = $connection->getDriver()->escapeIdentifier($sql); // table name } else { $this->sql = '(' . $sql . ') t'; // SQL command } $this->connection = $connection; }
fprintf($fd, "<table border=\"1\">\n\t\t<tr>\n\t\t\t<th>Test suite for PPA</th>\n\t\t</tr>\n"); fclose($fd); /* Loop on the servers given in the conf/config.inc.conf file */ foreach ($conf['servers'] as $server) { // Is this server in our list of configured servers? if (!in_array($server['desc'], $test_servers)) { continue; } /* connect to the server to get its version * and test its feature along the tests */ $_c = new Connection($server['host'], $server['port'], $server['sslmode'], $super_user[$server['desc']], $super_pass[$server['desc']], $server['defaultdb']); $_type = $data = null; if (!$_c->conn->isConnected()) { die("Connection to {$server['desc']} failed !\n"); } else { if (($_type = $_c->getDriver($platform)) === null) { die(printf($lang['strpostgresqlversionnotsupported'], $postgresqlMinVer)); } /* create the database handler we are going to use in the tests creator scripts */ include_once './classes/database/' . $_type . '.php'; $data = new $_type($_c->conn); $data->platform = $_c->platform; } fprintf(STDERR, "Connected to %s...\n", $server['desc']); if (!is_dir("{$test_static_dir}/{$server['desc']}")) { mkdir("{$test_static_dir}/{$server['desc']}"); } $fd = opendir($test_src_dir); $files = array(); while ($file = readdir($fd)) { if ($file != '.' && $file != '..') {
public function __construct(Connection $connection) { $this->connection = $connection; $this->driver = $connection->getDriver(); $this->identifiers = new HashMap([$this, 'delimite']); }
/** * Creates a database accessor */ function getDatabaseAccessor($database, $server_id = null) { global $lang, $conf, $misc, $_connection; $server_info = $this->getServerInfo($server_id); // Perform extra security checks if this config option is set if ($conf['extra_login_security']) { // Disallowed logins if extra_login_security is enabled. // These must be lowercase. $bad_usernames = array('pgsql', 'postgres', 'root', 'administrator'); $username = strtolower($server_info['username']); if ($server_info['password'] == '' || in_array($username, $bad_usernames)) { unset($_SESSION['webdbLogin'][$_REQUEST['server']]); $msg = $lang['strlogindisallowed']; include './login.php'; exit; } } // Create the connection object and make the connection $_connection = new Connection($server_info['host'], $server_info['port'], $server_info['sslmode'], $server_info['username'], $server_info['password'], $database); // Get the name of the database driver we need to use. // The description of the server is returned in $platform. $_type = $_connection->getDriver($platform); if ($_type === null) { printf($lang['strpostgresqlversionnotsupported'], $postgresqlMinVer); exit; } $this->setServerInfo('platform', $platform, $server_id); $this->setServerInfo('pgVersion', $_connection->conn->pgVersion, $server_id); // Create a database wrapper class for easy manipulation of the // connection. include_once './classes/database/' . $_type . '.php'; $data = new $_type($_connection->conn); $data->platform = $_connection->platform; /* we work on UTF-8 only encoding */ $data->execute("SET client_encoding TO 'UTF-8'"); return $data; }
/** * Import SQL dump from file. * @return int count of sql commands */ public static function loadFromFile(Connection $connection, $file) { @set_time_limit(0); // intentionally @ $handle = @fopen($file, 'r'); // intentionally @ if (!$handle) { throw new \RuntimeException("Cannot open file '{$file}'."); } $count = 0; $delimiter = ';'; $sql = ''; $driver = $connection->getDriver(); while (!feof($handle)) { $s = rtrim(fgets($handle)); if (substr($s, 0, 10) === 'DELIMITER ') { $delimiter = substr($s, 10); } elseif (substr($s, -strlen($delimiter)) === $delimiter) { $sql .= substr($s, 0, -strlen($delimiter)); $driver->query($sql); $sql = ''; $count++; } else { $sql .= $s . "\n"; } } if (trim($sql) !== '') { $driver->query($sql); $count++; } fclose($handle); return $count; }