I have a rather basic problem: I can't seem to connect CakePHP to my SQLite database. Surprisingly, I didn't find lots of information about it on the internet, though I may be looking up the wrong keywords. Nevertheless, this is my connection code:
var $default = array(
'driver' => 'sqlite',
'connect' =>'sqlite_popen',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => '',
'password' => '',
'database' => '/home/MY_USER_NAME/public_html/my_database.sqlite',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
Still, Cake only says "Cake is NOT able to connect to the database". Also, I don't know where to see the "real" logs (i.e., the error returned from the SQLite "driver"). So, I hit a dead-end. What should I do?
Thanks in advance.
As of CakePHP 2.0, Sqlite 3 is supported out of the box.
Be sure that sqlite is enabled in your PHP configuration:
phpinfo();
Inside app/Config/databases.php you can define Sqlite database like this:
public $default = array(
'datasource' => 'Database/Sqlite',
'persistent' => false,
'database' => 'my_database_name',
'prefix' => '',
'encoding' => 'utf8',
);
Now check your app/webroot/my_database_name.sqlite file.
SQLite3 is not officially supported yet by CakePHP... probably because the file attached to this bug/enhancement works.
https://trac.cakephp.org/ticket/3003
Grab the latest version of the file, update it with any newer patches, upload it to your cake/libs/model/datasources/dbo directory and configure it in your database.php file.
I am using a file called dbo_sqlite3.php
My configuration file uses this for the driver setting:
'driver' => 'sqlite3',
How to CakePHP with SQLite3:
Requirments:
CakePHP version 1.3
Datasources plugin
Steps:
Unpack the Datasources plugin in place.
Edit dbo_sqlite3.php and add:
App::import('Datasource','DboSource');
...just before the 'class' definition.
Use the following configuration in your database.php file:
var $default = array(
'datasource' => 'Datasources.DboSqlite3',
'login' => '',
'password' => '',
'database' => '/full/path/to/db.sqlite');
Done.
Are you trying to connect to a SQLite 3 database? CakePHP doesn't support them yet.
Other than that, you might want to try adding the leading / in your path. Seems like you're trying to do an absolute path but without the leading slash it's not going to do what you think it's going to do.
For cakephp 3.6 it should be like this:
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => '',
'password' => '',
'database' => 'C:\Bitnami\wampstack-5.6.39-0\apache2\htdocs\cake36\cake36.sqlite',
'schema' => 'test',
'prefix' => '',
'encoding' => ''
],
Related
I am a drupal8 developer. I want to connect to other external database in module. Likewise in D7 it's something like this:
$other_database = array(
'database' => 'databasename',
'username' => 'username', // assuming this is necessary
'password' => 'password', // assuming this is necessary
'host' => 'localhost', // assumes localhost
'driver' => 'mysql', // replace with your database driver
);
// replace 'YourDatabaseKey' with something that's unique to your module
Database::addConnectionInfo('YourDatabaseKey', 'default', $other_database);
db_set_active('YourDatabaseKey');
// execute queries here
db_set_active(); // without the paramater means set back to the default for the site
drupal_set_message(t('The queries have been made.'));
I tried this in D8 but it's throwing an error. Can you help me in this regard?
After connecting to the external DB you should clear your cache pragmatically.
Below is the code snippet:
$database = array(
'database' => <your_database_name>,
'username' => <your_username>,
'password' => <your_password>,
'host' => <host>,
'driver' => 'mysql',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql'
);
\Drupal\Core\Database\Database::addConnectionInfo('<your_key>', 'default', $database);
db_set_active('<your_key>');
drupal_flush_all_caches();
You can use db_set_sctive method in drupal 8 like this
\Drupal::Database->setActiveConnection($key)
I've seen that this question has been made Unsupported driver in laravel 4 when using laravel-oci8 package but the answere wasn't really usefull since the thread specify on https://github.com/yajra/laravel-oci8/issues/2 was resolved by just installing Oracle instant client and I already have it istalled.
I am trying to integrate oracle DB with laravel 5 app using yajra/laravel-oci8 package, I have folow the installation process and I have verified the specified requirements but with no success. When ever I try to run php artisan route:list or php artisan migrate it tells me that [InvalidArgumentException] Unsupported driver [oracle].
My Config/database.php is the following
...
'default' => 'oracle',
...
'connections' => [
'oracle' => array(
'driver' => 'oracle',
'host' => env('DB_HOST', 'localhost'),
'port' => '1521',
'database' => 'xe',
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'AL32UTF8',
'prefix' => '',
),
...
]
Am I missing any other configuration?
UPDATE
For anybody crossing this question.
The problem back then was that I incorrectly added the service provider (Yajra\Oci8\Oci8ServiceProvider::class,) class in the config/app.php
this is my config:
'oracle' => [
'driver' => 'oracle',
'tns' => "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = XE) (SID = XE)))",
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1521'),
'database' => env('DB_DATABASE', 'XE'),
'username' => env('DB_USERNAME', 'XEUSER'),
'password' => env('DB_PASSWORD', 'XEPASSWD'),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
],
change your config :
'oracle' => [
'driver' => 'oci8',
'host' => 'localhost',
'port' => '1521',
'database' => 'oracle_ID',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
'prefix_schema' => '',
],
to check : take on your controller function
$data = DB::connection('oracle')->table('your_table')->take(1)->get();
var_dump($data);
it works for me
I have followed the tutorial here, but any database connection is still hitting my primary development database locally.
http://code.tutsplus.com/tutorials/testing-like-a-boss-in-laravel-models--net-30087
Under app/config/testing I have defined database.php as per this tutorial and still it isn't connecting properly.
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
),
)
);
My bootstrap/start.php is as follows:
$env = $app->detectEnvironment(array(
'local' => array('macbook'),
));
According to everything I have read, Laravel should be able to define its own testing environment.
TIA.
It seems you havent rebuilt the autoloader classmap.
Try doing this in the terminal:
composer dump-autoload
We used webform-7.x-3.20 module in our web site.
But we want to connect and use a database different than Drupal's default database.
Below you can find example DB setting.
$databases['default']['default'] = array (
'database' => 'example_1',
'username' => 'example_1',
'password' => 'example_1',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => 'example_',
);
$databases['default2']['default'] = array (
'database' => 'example_2',
'username' => 'example_2',
'password' => 'example_2',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => 'example_',
);
As a conlusion we want to use the second DB in webform modules. The rest will used the first DB that is default.
We could not be succesful in realizing this.
Any help would be appreciated
in webform module you have to use the below code
db_set_active('default2');
After creating multiple fields with the help of the installation profile I am now also trying to figure out how I can add the allowed file extensions in the installation profile. Here is my code so far:
'name' => 'attachment',
'type' => 'file',
'settings' => array(
'allowed_file_extensions' => array('txt pdf'),
),
The allowed_file_extensions was just a test to see if it works but it doesn't it gives an fatal PHP error. (** PHP Fatal error: Unsupported operand types** )
How can I add the file extensions at the field?
PS: I also tried putting the settings in the instance, this gives the same error.
Oke, I was having this problem for the last three days. Now after a few hours after I posted this question I solved the problem.
For those who have the same question or problem here is what solved it for me and what the right way is to add settings. The settings can be different for each instance so the settings go at the instance creation and not the field itself.
Here is an example on how it is supposed to be:
$instance = array(
'field_name' => 'file'
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Attachment',
'description' => 'Add an attachment here',
'required' => TRUE,
'settings' => array(
'max_filesize' => '512',
'file_extensions' => 'zip txt pdf docx'
),
);
field_create_instance($instance);
The settings field is not required but i was using an foreach because I generate multiple fields and instances at once, if you do this and you have settings at 1 of your generated field instances then you have to add settings at all instances or check if it is there or not.
I hope my experience can help any of you out when having the same problem.