I'm building a webapp which have two databases:
First: Database for user registrations, sign up etc. / in MySQL
Second: Database for the stock market data / in PostgreSQL
First database (MySQL) works without any problem.
But the second one (PostgreSQL) doesn't work.
This is my env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=panel
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION_SECOND=pgsql
DB_HOST_SECOND=localhost
DB_PORT_SECOND=5432
DB_DATABASE_SECOND=assets_daily_info
DB_USERNAME_SECOND=postgres
DB_PASSWORD_SECOND=1234
And here is the database config php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST_SECOND', '127.0.0.1'),
'port' => env('DB_PORT_SECOND', '5432'),
'database' => env('DB_DATABASE_SECOND', 'forge'),
'username' => env('DB_USERNAME_SECOND', 'forge'),
'password' => env('DB_PASSWORD_SECOND', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
I made a Model where I want to get data from PostgreSQL database:
namespace App\Models;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
class Thepage extends Model
{
protected $connection = 'pgsql';
protected $table = 'queue_stats';
protected $fillable = [
'buyqueue', 'sellqueue', 'timestamp',
];
}
And finally, here is the controller:
class Thepage Controller extends Controller
{
public function index()
{
$queues = Thepage::all();
return view('pages.queue-stats',compact('queues'));
}
}
The problem is that laravel can't find the driver, it just shows:
Illuminate\Database\QueryException could not find driver (SQL: select * from "queue_stats")
I double checked apache's and php's .ini files, extension pdo_pgsql and pgsql are uncommented in both files.
I tried clear cache and config cache, nothing happened and I still get this annoying error.
Where am I doing wrong?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire