SQLSTATE[HY000] [2002] Connection refused in laravel - laravel-5.7

i have this problem with laravel, this is my .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_DEBUG=true
APP_URL=
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_db_name
DB_USERNAME=root
DB_PASSWORD=
and this is my config/database
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
i alway get error message SQLSTATE[HY000] [2002] Connection refused, i was changed DB_HOST=127.0.0.1 to DB_HOST=localhost but it's not working.
this is my issue, thanks for help

Add APP_URL=http://localhost in .env file.
Hope it will work

You need to increase the server ram and the problem will be solved :)

Related

SQLITE not working with Codeigniter in Exeoutput4PHP

In my Codeigntier Project under EXEOUTPUT4PHP, I have set databse.php file as below:
$db['default'] = array(
'dsn' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => '../dbname.db',
'dbdriver' => 'sqlite3',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
In PHP Settings-> PHP Extensions option of EXEOUTPUT4PHP, I have compiled php_pdo_sqlite.dll and php_sqlite3.dll into exe
In PHP.ini, I have uncommented the lines: extension=php_pdo_sqlite.dll and extension=php_sqlite3.dll
Still on running the application, I am getting the following error:
#### An uncaught Exception was encountered
Type: Error
Message: Class 'SQLite3' not found
Filename: EXELocation\Data\system\database\drivers\sqlite3\sqlite3_driver.php
Line Number: 89
Backtrace:
File: EXELocation\Data\application\models\User_model.php
Line: 6
Function: database
File: EXELocation\Data\application\controllers\User.php
Line: 8
Function: model
File: EXELocation\Data\index.php
Line: 315
Function: require_once

How to connect external database at run time in custom module drupal 8

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)

Unsupported driver [oracle] in Laravel 5 when using yajra/laravel-oci8

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

Ability to use other databases in the web form module

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');

How do I connect CakePHP to a SQLite database?

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' => ''
],

Resources