AnyDataset provides a common class called
DBDataSet for connect to a relational databases. An example on how to connect is defined below:
$db = new DBDataSet('conn_name'); $iterator = $db->getIterator('select * from some_table');
In this example, the
conn_name is the alias for the connection defined in the file
return [ 'connections' => [ 'conn_name' => [ 'url' => 'pdodriver://root@localhost/dbname', 'type' => 'dsn' ] ] ];
The fields available are:
- type (optional and constant: dsn)
This field is just an alias for the connection string. It is a good idea to abstract the details of the database from the source code. It need to have a connection string url.
Url Connection String
The connection string is look like an url. For example:
The driver is any PDO driver available in your PHP installation. The list of all existing PDO drivers is available here. The driver name is the name of the PDO extension, without the 'pdo_' by default.
XMLNuke have two special drivers. One is a driver for the SQLRelay. SQLRelay is a persistent database connection pooling, proxying, load balancing and query routing system for Unix and Linux. Another driver is a native implementation of the Oracle OCI8 library. This is necessary because the PDO Oracle driver still EXPERIMENTAL and some platforms could not install this driver.
The driver name for SQLRelay is
sqlrelay and the driver name for oracle native implementation is
Another possibility is to connect to a database is file based. The DSN syntax is:
DRIVER:///path[?PARAMETERS] or DRIVER://C:/PATH[?PARAMETERS]
Below some real examples:
Connect to MySQL at server localhost and database test identified by 'root' with no password:
Connect to MySQL at server localhost and database test identified by 'root' and password '1234'
Connect to a SQL Lite database at /data/users.sqlite
Connect to a SQLRelay instance 'test' at the server '192.168.1.3' identified by 'joao' and password '1234'