Phork was built using MySQL, although it can be extended to use numerous other SQL databases. In order to add another database class it must implement the Sql interface and extend the DatabaseAdaptor class. To use a new database class change $arrDatabase['Type'] to the new class name in the database configuration.
The bootstrap automatically sets up the database using the DatabaseFactory class. The database classes are in phork/php/database/. There's also a database configuration file.
//connect to the database and set it up for reads
$objDb = AppRegistry::get('Database');
if ($objDb->initRead(true)) {
//run the select query
if (($mxdResult = $objDb->read("SELECT * FROM mytable LIMIT 10")) !== false) {
while ($arrRow = $objDb->fetchRow($mxdResult)) {
//do something with $arrRow here
}
$objDb->freeResult($mxdResult);
}
}
//connect to the database and set it up for writes
$objDb = AppRegistry::get('Database');
if ($objDb->initWrite(true)) {
//run the insert query
if (($mxdResult = $objDb->write("INSERT INTO mytable (foo, bar) VALUES ('abc', 'def')")) !== false) {
//make sure a result was returned and get the inserted ID
if ($blnResult = ($mxdResult != false)) {
$intId = $objDb->getInsertedId();
}
$objDb->freeResult($mxdResult);
return $blnResult;
}
}
//connect to the test database
$objDb = AppRegistry::get('Database');
if ($objDb->initConnection('Test', true)) {
//run the select query
if (($mxdResult = $objDb->read("SELECT * FROM mytable LIMIT 10")) !== false) {
while ($arrRow = $objDb->fetchRow($mxdResult)) {
//do something with $arrRow here
}
$objDb->freeResult($mxdResult);
}
}