Error: Adapter Phalcon\Db\Adapter\Pdo\Mysql is not supported, HOWEVER

181 views Asked by At

Edit:

Phalcon version 4.2.0 and php 7.4.3 versions are the compatible versions I was told to used and Im sure that I had scaffolded the users table. But now when I am trying to rescaffold since I added new columns to that table, its telling me Error: Adapter Phalcon\Db\Adapter\Pdo\Mysql is not supported I've checked php -m in command prompt and it says the mysql pdo exists. I dunno what else to do.

Config.php - Here is the file that has the database configuration. Since I already had users scaffolded, I could have checked if users exist and it returned true or false. So I knew this was working before. <?php

use Phalcon\Config;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

    $config = new Config([
        'database' => [
        'adapter'  => DbAdapter::class,
        'host'     => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname'   => 'medical',
    ],
    'application' => [
        'controllersDir' => __DIR__ . '/../app/controllers/',
        'modelsDir'      => __DIR__ . '/../app/models/',
        'viewsDir'       => __DIR__ . '/../app/views/',
        'baseUri'        => '/',
    ],
    ]);

    return $config;

services.php - this is where the config for the database information was set from the config.php file

   //set the database
    $db = $container->get('config');
    $databaseConfig = $config->database;
    $host = $databaseConfig->host;
    $username = $databaseConfig->username;
    $password = $databaseConfig->password;
    $dbname = $databaseConfig->dbname;

also, php.ini has the following:

extension=bz2
extension=curl
;extension=dba
extension=com_dotnet
;extension=enchant
;extension=ffi
extension=fileinfo
;extension=ftp
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
1

There are 1 answers

0
Arthur On

services.php is not registering the db service. It should look like:

$config = $container->get('config');

$container->setShared('db',
     function () use ($config) {
        return new DbAdapter(
            [
                'host' => $config->host,
                'username' => $config->username,
                'password' => $config->password,
                'dbname' => $config->dbname
            ]
         );
     }
);

To check that it is working, run a simple query:

echo $container->get('db')->fetchColumn('SELECT count(*) FROM `table`');

With this first step we can check that the connection to your db is working and the container has a db service. If the check is successful, please share the declaration of your model and your loader. Also, keep into account that your config.php file should be registered in the container as well; according to your example:

 use Phalcon\Config;

 $config = require_once 'config.php';

 $container->set('config',$config);