davideairaghi / php

repository of php code
Apache License 2.0
12 stars 9 forks source link

Uncaught exception 'PDOException' with message 'could not find driver' #4

Open biletnam opened 6 years ago

biletnam commented 6 years ago

good afternoon I ask to prompt in what I am mistaken at usage of your class Phalcon version 3.2.4 PHP 5.6.32

Connection settings $ mc = array ( 'adapter' => '\ Airaghi \ PhalconPHP \ MSSQL \ Adapter \ Mssql', 'host' => "server name", 'username' => "", 'password' => "", 'dbname' => 'DB', 'pdoType' => 'sqlsrv', 'dialectClass' => '\ Airaghi \ PhalconPHP \ MSSQL \ Dialect \ Mssql' ); But when trying to use the connection, the following error is returned Notice: Undefined index: pdoType in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 225 Notice: Undefined index: host in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 226 Notice: Undefined index: dbname in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 227 Notice: Undefined index: username in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 230 Notice: Undefined index: password in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 231 Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php:232 Stack trace:

0 C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php(232): PDO->__construct(':server=;databa...', NULL, NULL)

1 C:\Storages\IIS\inetpub\mptk3\test.php(55): Airaghi\PhalconPHP\MSSQL\Adapter\Mssql->connect()

2 {main}

thrown in C:\Storages\IIS\inetpub\mptk3\app\library\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql.php on line 232

davideairaghi commented 6 years ago

Hi, db configuration should be placed in file app\config\config.php. See the following example

return new \Phalcon\Config(array(
    'database' => array(
        'adapter'     => '\Airaghi\PhalconPHP\MSSQL\Adapter\Mssql', 
        'host'        => 'db_servername',
        'username'    => 'db_username',
        'password'    => 'db_password',
        'dbname'      => 'db_name',
       'pdoType'       => 'sqlsrv',
       'dialectClass'   => '\Airaghi\PhalconPHP\MSSQL\Dialect\Mssql'
    ),
    'application' => array(
        'controllersDir' => __DIR__ . '/../../app/controllers/',
        'modelsDir'      => __DIR__ . '/../../app/models/',
        'viewsDir'       => __DIR__ . '/../../app/views/',
        'pluginsDir'     => __DIR__ . '/../../app/plugins/',
        'libraryDir'     => __DIR__ . '/../../app/library/',
        'cacheDir'       => __DIR__ . '/../../app/cache/',
        'htmlDir'        => __DIR__ . '/../../app/html/',
        'baseUri'        => '/',
    )
));
biletnam commented 6 years ago

Thank you for such an operatic response Tell me to put this connection in a separate configuration file, you can not use it without this selection In this case, I need to use the Micro application

davideairaghi commented 6 years ago

i never used a microapplication with these two classes, you can debug the situation by dumping the variable $descriptor before using it in \Airaghi\PhalconPHP\MSSQL\Adapter\Mssql::connect