In order to be able to query SQL databases (eg: MySQL), you first need to open bootstrap index.php file and add this event listener:
then create in stdout.xml a <server> tag (which will hold your connection settings), child of DEVELOPMENT ENVIRONMENT tag (because credentials will be different on another environment), child of <nosql> tag. Example:
<nosql> <local> <server driver="redis" host="localhost"/> </local> </sql>
If your site uses multiple database servers for a single DEVELOPMENT ENVIRONMENT, it is allowed to have multiple <server> entries there. To learn more how to configure this tag and drivers supported, check official documentation!
Querying NoSQL databases requires you completed setting NoSQL databases section!
If you have a single server per DEVELOPMENT ENVIRONMENT, to get a connection, use:
$connection = Lucinda\NoSQL\ConnectionSingleton::getInstance();
If you are having multiple servers per DEVELOPMENT ENVIRONMENT, use this instead
$connection = Lucinda\NoSQL\ConnectionFactory::getInstance(SERVER_NAME);
Where SERVER_NAME is value of "name" attribute at matching <server> tag.
Both will return a single Lucinda\NoSQL\Driver per session, reused until script ends and automatically closed afterwards (unless driver is apc/apcu, requiring no connections).
Once a connection is retrieved, you can run basic document database logic such as:
$connection->set(KEY, VALUE, EXPIRATION);
// saves a key named "foo" with value "bar" in DB that expires in 10 seconds $connection->set("foo", "bar", 10); // retrieves value of "foo" from DB $x = $connection->get("foo");
This works the same way as PDO, hiding complexities of driver used. If, however, basic operations are not enough and you need to work with actual vendor logic use:
$vendorDriver = $connection->getDriver();
then use vendor official documentation (eg: redis) to query that object.