Skip to main content

Passing Parameters to PDODriver

You can pass parameter directly to the PDODriver by adding to the connection string a query parameter with the value.

e.g.

<?php
$uri = Uri::getInstanceFromUri("mysql://root:password@localhost")
->withQueryKeyValue(PDO::MYSQL_ATTR_COMPRESS, 1);
$db = Factory::getDbInstance($uri);

Special Parameters

AnyDatasetDB has some special parameters:

ParameterValueDescription
DbPdoDriver::STATEMENT_CACHEtrueIf this parameter is set with "true", anydataset will cache the last prepared queries.
DbPdoDriver::DONT_PARSE_PARAMany valueIs this parameter is set with any value, anydataset won't try to parse the SQL to find the values to bind the parameters.
DbPdoDriver::UNIX_SOCKETpathPDO will use "unix_socket=" instead of "host=".
e.g.
$uri = Uri::getInstanceFromString("sqlite://" . $this->host)
->withQueryKeyValue(DbPdoDriver::STATEMENT_CACHE, "true")
->withQueryKeyValue(DbPdoDriver::DONT_PARSE_PARAM, "");

If using UNIX_SOCKET:

# Note: there is 3 slashes after the protocol, the first one is the separator between the protocol and the host
$uri = Uri::getInstanceFromString("mysql:///" . $this->dbname)
->withQueryKeyValue(DbPdoDriver::UNIX_SOCKET, "/run/mysql.sock");