Have anyone used Oracle Database with Kirby yet? Been searching but unable to find something related to Kirby.
All I can find are Laravel implementations.
Would really appreciate if someone could point or help me make this connection.
Thank you.
Have anyone used Oracle Database with Kirby yet? Been searching but unable to find something related to Kirby.
All I can find are Laravel implementations.
Would really appreciate if someone could point or help me make this connection.
Thank you.
Oracle databases are not supported by default because they are not as common as MySQL and SQLite, but you can create a database connector in a plugin:
/site/plugins/oracle-connector/index.php
oracle
with the appropriate DSN definition
You should then be able to configure an Oracle database in your config and/or directly in your code.
PS: Please set a category when creating new topics. This makes it clearer whether you are referring to v2 or v3 and also saves us work.
Thanks. So far I have this. Am I getting there?
Question though is where would the $user and $password be used in the connection?
/sites/plugins/oracle-connector/index.php
<?php
use Exception;
use Kirby\Exception\InvalidArgumentException;
/**
* Oracle database connector
*/
Database::$types['oracle'] = [
'dsn' => function ($host, $port, $database) {
if (isset($host) === false) {
throw new InvalidArgumentException('The oracle connection requires a "host"');
}
if (isset($database) === false) {
throw new InvalidArgumentException('The oracle connection requires a "database" parameter');
}
return 'oci:dbname=' . $host . ':' . $port . '/' . $database;
}
];
/site/config/config.php
<?php
return [
'db' => [
'type' => 'oracle',
'host' => 'remoteserver.com',
'port' => '9999',
'database' => 'myoracledb',
'user' => 'user',
'pass' => 'pass'
]
];
User and password are handled by Kirby, so you donβt need to do anything here.
This means that your config needs to look like this to be picked up by Kirby:
<?php
return [
'db' => [
'type' => 'oracle',
'host' => 'remoteserver.com',
'port' => '9999',
'database' => 'myoracledb',
'user' => 'user',
'password' => 'pass'
]
];
Great.
Do I have to include all these lines on my index.php?
namespace Kirby\Database;
use Exception;
use Kirby\Exception\InvalidArgumentException;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Str;
use PDO;
use PDOStatement;
use Throwable;
Or it should only contain the connector part?
Thanks for the help.
Actually you only need this:
<?php
use Kirby\Database\Database;
use Kirby\Exception\InvalidArgumentException;
/**
* Oracle database connector
*/
Database::$types['oracle'] = [
'dsn' => function (array $params) {
if (isset($params['host']) === false) {
throw new InvalidArgumentException('The oracle connection requires a "host"');
}
if (isset($params['port']) === false) {
throw new InvalidArgumentException('The oracle connection requires a "port"');
}
if (isset($params['database']) === false) {
throw new InvalidArgumentException('The oracle connection requires a "database" parameter');
}
return 'oci:dbname=' . $params['host'] . ':' . $params['port'] . '/' . $params['database'];
}
];
You only need to import the classes you are actually using in your code.
I have also fixed the argument to the function (which is always an array with all params).
This is great.
Thank you so much!
You are welcome.