I am using two Docker container, one having ubuntu and an apache webserver running, the other one a mysql server. The containers are linked and i can connect from the ubuntu container onto the mysql server. For the connection I use in the ubuntu container:
mysql -u root -h mysql
where the second 'mysql' is the name of the container. I can connect to it through the container id as well, so the connection works as well as connecting onto the database from the windows environment.
What doesnt work is the connection from doctrine to the database within the PHP application which is in the ubuntu container.
The config looks like this:
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'mysql',
'port' => '3306',
'user' => 'root',
'password' => '',
'dbname' => 'db_name',
'charset' => 'utf8',
)
)
),
)
But I get the Error message
Uncaught PDOException: could not find driver in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php
and
Zend\ServiceManager\Exception\ServiceNotCreatedException: An abstract factory could not create an instance of doctrine.entitymanager.ormdefault(alias: doctrine.entitymanager.orm_default). in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php
Does anyone have any idea how to solve this and where exactly the error comes from?
I have already tried to put in the container ID as 'host' and commented out the 'password' field as it is not used.
Thanks in advance
Jonathan
You need to have pdo_mysql allowed on your system, it doesn't seem a connectivity issue but a php configuration problem.
Can you try to do this command inside your php container
php -i | grep pdo_mysql
Just to understand if php has this module
I have put PushChatServer dir in htdocs folder and create database puschat try to run #"http://localhost/PushChatServer/api/test/database.php"
Then I got following exception.
I want do same thing to explain this link http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2
I have done all that but I got this exception
Could not connect to the database. Reason: exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/PushChatServer/api/test/database.php:17 Stack trace: #0 /Applications/MAMP/htdocs/PushChatServer/api/test/database.php(17): PDO->__construct('mysql:host=loca...', 'root', 'root', Array) #1 {main}
You need to change host from localhost to 127.0.0.1
Laravel 4: In your app/config/database.php try changing host from localhost to 127.0.0.1
Laravel 5: In the .env file, change DB_HOST from localhost to 127.0.0.1
Source: PDOException SQLSTATE[HY000] [2002] No such file or directory
Quick test (run in shell):
php -r "new PDO('mysql:host=localhost;dbname=test', 'username', 'password');"
SQLSTATE[HY000] [2002] No such file or directory means php cannot find the mysql.default_socket file. Fix it by modifying php.ini file. On Mac it is mysql.default_socket = /tmp/mysql.sock (See MySQL connection not working: 2002 No such file or directory)
SQLSTATE[HY000] [1044] Access denied for user 'username'#'localhost' CONGRATULATION! You have the correct mysql.default_socket setting now. Fix your dbname/username/password.
Also see Error on creating connection to PDO in PHP
I had the same error using PHP 5.6.30 (macOS Sierra) with the simple PDO code like:
$pdo = new PDO('mysql:host=localhost;dbname=db_php', 'root', '');
And I received the same error message. To fix, I changed "localhost" for IP (loopback) "127.0.0.1" in my code:
$pdo = new PDO('mysql:host=127.0.0.1;dbname=db_php', 'root', '');
To test the connection:
$ php -r "new PDO('mysql:host=127.0.0.1;dbname=db_php', 'root', '');"
This work's for me!
Restart your database and local web server:
sudo service mysqld restart
It should work!
I'm not sure if this will work for you; but I use CakePHP, and I get this error whenever I forget to put the port number at the end of the 'host'.
Hope this helps!
Before
'test' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'database' => 'mylogin',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_TEST_URL', null),
]
After
'test' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost:8080',
'username' => 'root',
'password' => 'root',
'database' => 'mylogin',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_TEST_URL', null),
]
PDO treats localhost very particularly:
From http://php.net/manual/en/ref.pdo-mysql.connection.php:
Note: Unix only: When the host name is set to "localhost", then the
connection to the server is made thru a domain socket. If PDO_MYSQL is
compiled against libmysqlclient then the location of the socket file
is at libmysqlclient's compiled in location. If PDO_MYSQL is compiled
against mysqlnd a default socket can be set thru the
pdo_mysql.default_socket setting.
That why PDO and mysql_connect will give different behavior for localhost.
So, if you want to use a TCP connection with PDO, never use localhost but 127.0.0.1.
I had the same error for Mysql PDO, this code works for me!
<?php
$dsn = 'mysql:host=127.0.0.1;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
$dbh = new PDO($dsn, $username, $password, $options);
?>
got this code from : http://php.net/manual/en/ref.pdo-mysql.connection.php
Run the following command in shell, I think it will help.
php artisan cache:clear
php artisan config:clear
php artisan view:clear
On Mac OSX/MAMP you may find a mysql.sock.lock file in your /Applications/MAMP/tmp/mysql folder.
You can safely remove the file mysql.sock.lock and you should be in good shape.
Just ran into this same issue and the problem is the password. In the tutorial the author lists the password as:
"d]682\#%yl1nb3"
So as per the suggestion given by #Marki555, I looked in the config file - api_config.php. and the password listed there is:
"d]682\#%yI1nb3"
The upper case 'I' is what caused the issue because the password you set for user on the db has the password with the lowercase l but it really is looking for the uppercase I. After I changed the pushchat user's password to have an uppercase i, it worked!
I have this issue:
CakePHP is NOT able to connect to the database.
Database connection "Sqlserver" is missing, or could not be created.
Details of what I've had so far:
public $default = array(
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'host' => 'localhost\SQLEXPRESS',
'login' => 'login',
'password' => 'pass',
'database' => 'prueba',
'prefix' => '',
'encoding' => 'utf8'
);
and in my xampp\php\php.ini I had this:
[PHP_SQLSRV]
extension=php_sqlsrv_55_ts.dll //this file exists in xampp\php\ext
[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_55_ts.dll //this file exists in xampp\php\ext
I am using:
XAMPP 3.2.1
SQL Server 2008 R2
PHP 5.5.19
CakePHP 2.6.3.
This works without the framework, but within the Cakephp framework it does not work. Why?
Have you tried to install Microsoft ODBC Driver for SQL Server ?
In order to get pdo_sqlsrv work you have to install Microsoft ODBC Driver
I'm trying to install Zend Framework 2 + Doctrine from this manual and have some problem with PDO driver. Doctrine is trying to connect to my MySQL server and then trying to create schema:
./vendor/bin/doctrine-module orm:schema-tool:create
I have this error:
[PDOException]
could not find driver
This is my config/autoload/doctrine.local.php:
return array( 'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'password',
'dbname' => 'blog',
)))));
I have PHP 5.3.5 and i have uncommented ;extension=php_pdo_mysql.dll in php.ini, also it wasn't commented. But php -m | grep -i pdo gives me:
PDO
only. I'm know that it should be pdo_mysql too, but i'm trying everything and it isn't appear.
Anyway, PDO driver is works well at my another project on this server, where I'm not using Zend and Doctrine.
Ohh yes. I'm just solved a problem. I'm going to this page and thought to find my php.ini files anywhere else perhaps PHP folder - it was one more in "C:\Users\%username%\AppData\Local\VirtualStore\Program Files (x86)\wamp\bin\php\php5.3.5" and there row
;extension=php_pdo_mysql.dll
weren't uncomment. I'm uncommented it and it works!
I can't connect to MSSQL Server. I've been researching for 2 days, yet I can't find any useful resources. This is the error I'm getting:
URL rewriting is not properly configured on your server.
Help me configure my database. I don't / can't use URL rewriting:
Your tmp directory is writable.
The FileEngine is being used for caching. To change the config edit APP/config/core.php
Your database configuration file is present.
Here's my database config file:
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mssql',
'persistent' => false,
'host' => 'Charmae-PC\Charmae',
'login' => 'sa',
'password' => 'pass',
'database' => 'obbm',
'prefix' => '',
'port' => '',
);
}
What should I do?
You need to configure your database with cakephp[windows php driver]. I don't know which version cakephp are you using. But for any version of cakephp and wampserver windows php drivers are different. for more information
Download the sqlsrv driver from here
and then the rest of configuration.
By the way you have to use sqlsrv driver for config/database.php
var $default = array(
'driver' => 'sqlsrv',
...