Can not connect to Db- Dump using codeception - pdo

I am struggling to use the db functionality of codeception framework. The error i am getting is
Db: could not find mysql driver while creating PDO connection
actor: AcceptanceTester
modules:
enabled: [Db, PhpBrowser]
config:
Db:
dsn: "mysql:host=localhost;dbname=my_db"
user: 'root'
password:
populate: true
cleanup: true
dump: 'tests/_data/Dump20180423.sql'
PhpBrowser:
url :
My acceptance.suite.yaml file is set like this.
Also my dump file has the CREATE TABLE command inside.
The path for Mysql is already set in the environmental variables path.
The pdo extensions are set inside my php.ini file
I guess it's a problem with the dsn as it fails before validating my user credentials. Also my mysql works fine. I have projects that i use PDO connection and they work without any issue.
I tried every solution i could find but still getting the same error. Thank you in advance for any help!!!

So after many hours/days i finally found out the solution to this. The problem was coming from my cygwin (linux console). While my php.ini file was fine and php info was sawing i had pdo_mysql installed and everything seemed like that, cygwin had a different opinion. I had to install pdo_mysql inside cygwin so the command :
php vendor/bin/codecept run could connect to the database and work!!!
Typing php -m in my cygwin console showed me that i was missing this module (pdo_mysql).
After that the problem is solved and my tests work fine.

Related

Symfony 5 - "An exception occurred in driver: could not find driver"

I'm currently face to this problem. I am really new beginer at Symfony.
Problem :
When i create a new db with cli symfony console doctrine:database:create, i am getting these errors :
In AbstractPostgreSQLDriver.php line 102:
An exception occurred in driver: could not find driver
In Exception.php line 18:
could not find driver
In PDOConnection.php line 38:
could not find driver
Iam using php 7.4 with xampp and normaly pdo_sql is installed :
extension=bz2
extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
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
;extension=pgsql
;extension=shmop
this is my .env file config :
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://root:#127.0.0.1:3306/dbname"
DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###
And this is my doctrine.yaml file config :
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
I have been searching for hours but i cant get any solutions to solve my problem, someone has an idea ?
I'm on windows.
Thanks a lot !
If you want to use Mysql , comment this line DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
If not comment the other line
if you are working in Linux, probably some extensions are missing,run those command
sudo apt-get install php-mysql php-pdo
I had the same problem, PHP 7.4.29, xampp, windows.
For the purpose of installing Xdebug I upgraded my PHP version to 7.4.29 (previously 7.4.18), and I guess this errror occured since then. Database connexion worked before. I copied the extensions from the old php.ini to the new one and the error remained.
What resolved the problem : added this line :
extension_dir = "D:\programs\xampp\php\ext"
And activated these extensions :
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=mbstring
extension=exif
extension=mysqli
extension=pdo_mysql
extension=pdo_sqlite
In my case, I got my .env.local file from a colleague and stupidly saved it without the leading dot, so Symfony was using the values from the .env file, which reads
DATABASE_URL="postgresql://symfony:ChangeMe#127.0.0.1:5432/app?serverVersion=13&charset=utf8" rather than the correct DATABASE_URL="mysql://foo:bar#127.0.0.1:3306/baz?serverVersion=mariadb-x.y.z" from .env.local.
I'm running Homestead/vagrant on windows and my problem was, I wasn't able to execute this command php bin/console doctrine:database:create on windows even though I opened a terminal as administrator
As seen on these 2 pictures I tried Cmder and Git bash and both of them failed, saying an execption occured in driver: could not find driver
I then solved it by SSH into my vagrant box vagrant ssh navigated to the working symfony folder and ran the command from there php bin/console doctrine:database:create and for some reason that worked !
I wish there was an easier way to debug this stuff, but I guess that's how it is working with Windows. Hope this can help someone out there
php.ini
copy path
find the file then open it
delete the ; in extension=mysqli
I also had this problem, just uncomment the DATABASE_URL that you have on your computer either (sqlite, mysql or postresql).
I had the same problem when I typed the following command:
symfony console make:user User
I solved the problem with the command:
php bin/console make:user User.
Wanting to create a user
step 1 => go to Xaamp control panel then click config of Apache
step 2 => click on PHP(php.ini).browse through the file. you can able to see these extensions.
extension=bz2
extension=curl
remove ; from ;extension=pdo_pgsql and save it and close file
step 3 => now come back to your project.click on .env file and comment this line:
DATABASE_URL="postgresql://symfony:ChangeMe#127.0.0.1:5432/app?serverVersion=13&charset=utf8"
this works!
I had the same problem, I am runing a Symofny application with docker.
When you add doctrine-bundle to your app, in Dockerfile will appear this lines what will install drivers for postgres.
You have to remove it and add this line, this will install drivers for mysql
RUN docker-php-ext-install pdo pdo_mysql
I hope that helps to someone.
Delete or comment from .env file the line:
DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
I had the same problem to solve the problem:
type php --ini to see the path to the file php.init
if you are on vscode do ctr + click on the path otherwise follow the path manually on your computer to the file php.init make sure your open php.init file with admin right !!
edit the file and uncomment extension=pdo_mysql
save and retry php bin/console doctrine:database:create
type php -m for check if your're in list pdo_mysql
here an illustration

Is there a better way than this to run an SQL script through puppet?

Take a look at Get puppet build to fail when the contained SQL script fails execution
I was attempting to run a vagrant build which installs Oracle XE in an Ubuntu Virtualbox VM and then runs a an SQL script to initialize the Oracle Schema. The vagrant build is here : https://github.com/ajorpheus/vagrant-ubuntu-oracle-xe. The setup.sql is run as a part of the oracle module's init.pp (right at the bottom or search for 'oracle-script').
When running the SQL script as a part of the vagrant build, I see the following error:
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: Error 6 initializing SQL*Plus
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: SP2-0667: Message file sp1<lang>.msb not found
notice: /Stage[main]/Oracle::Xe/Exec[oracle-script]/returns: SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
There were two things that were instrumental in me finding a workaround for the problem:
As suggested in this answer, setting the logoutput attribute to true for the exec block under question immediately showed me the error, whereas before the exec was just failing silently.
It seemed strange that I was able to run the command (sqlplus system/manager#xe < /tmp/setup.sql) after manually logging in as the 'vagrant' user. That suggested that there was something missing in the environment. Therefore, I copied all ORACLE env. vars into the exec as seen on Line 211 here
That worked, however, setting up the env vars manually seems a bit brittle. Is there a better way to setup the ORACLE environment for the vagrant user? Or, is there a way to get puppet to setup the environment for the vagrant user similar to an interactive shell?
If some profile has been set up to give the user a working interactive shell, you should be able to pass your action through such a shell
command => 'bash -i -c "<actual command>"'
As an aside about logoutput, since you mentioned that - the documentation advises that "on_failure" is a sane default, as it will only bloat your output when there are actual errors to analyze. It is the actual default in the latests versions of Puppet.

Laravel3 migration on production server error: SQLSTATE[HY000] [2002] No such file or directory

I tried my database migration in fortrabbit.com through SSH, but I got an error:
SQLSTATE[HY000] [2002] No such file or directory
How to specify database name, password of production database?
How to do Laravel3 migration via SSH access in production server. I have used pagodabox it was working fine but very costly, so I switched to fortrabbit.com.
I tried this http://forums.laravel.io/viewtopic.php?id=6177, but no solution.
We surely will need more info about your problem.
To do a migration on Laravel using ssh, you basically have to go to your app folder and execute php artisan migrate. But I think you know that, right?
To specify your database infor for production,
1.create a ditectory production inside your app/config
2.copy your current app/config/database.php to it
3.edit your new app/config/production/database.php
4.on your app/start/global.php, configure your environment:
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
'production' => array('example.com')
));
But to clarify it even better, you can watch this fresh video from Jeffrey Way on Laracasts:
https://laracasts.com/lessons/from-zero-to-deploy-with-fortrabbit

The local psql command could not be located

I'm following the instructions found here.
When I try to run $ heroku pg:psql or $ heroku pg:psql HEROKU POSTGRESQL_BROWN I recieve the following error message:
! The local psql command could not be located ! For help
installing psql, see local-postgresql
I can't find anything useful on the link it gives me (it just links to the instructions I was already using, but further down the page) nor can I find this error anywhere else.
If I've missed anything you need to know to answer this, just let me know. I'm rather new to all this and teaching myself as I go.
I had same error even after installing Postgres locally.
But after seeing this
I saw that "pqsl" was not in the PATH so I then did
PATH=%PATH%;C:\Program Files\PostgreSQL\9.2\bin
which worked for me
I have since solved this myself. When I ran heroku pg:info it says the version number is 9.1.8, I was locally running 9.2
installing 9.1.8 and ensuring Path pointed to the appropriate folder solved the problem.
After you change the path, make sure to restart the terminal!
Set the PATH. To find out the PATH of your psql script (on mac) open the sql shell script from your finder in Applications/Postgres installation. This will give you a hint as to where it is installed. That opened a window which told me it is located here: /Library/PostgreSQL/8.4/scripts/runpsql.sh
Then, I set the PATH variable from the terminal window by typing:
$ PATH="/Library/PostgreSQL/8.4/bin:$PATH"
(depends on the location of your PostgreSQL installation, find your bin path first, another exp: /usr/local/Cellar/postgresql#9.6/9.6.8/bin)
OR.....
You can also connect to the shell by opening the shell directly from your postgres installation folder. Then enter the credentials. If you don't know the credentials, here is how to find them out:
$ heroku pg:info
=== HEROKU_POSTGRESQL_RED_URL (DATABASE_URL)
$ heroku pg:credentials HEROKU_POSTGRESQL_RED_URL
Top answer wouldn't work for me oddly, my system would not add the Path via cmd with administrator access (Not sure why).
So check this > Windows key > environment variables > system variables
And add the last line (your version may differ in the path)
Make sure you've installed the toolbelt as psql is installed by default.
However you also need to ensure you've installed a local copy of PostgreSQL; if you don't the toolbelt will be unable to find the native psql client.
Assuming you have installed a local copy of PostgreSQL, make sure you can execute psql from the command line directly (i.e make sure you PATH is set correctly ). If the command does not execute, check your PATH, if it does execute see if you can connect via the PSQL connection string provided in the Heroku control panel. If you can connect reinstall the toolbelt, if you are unable to connect provision another dev database and try again.
If there are still issues, I would suggest contacting Heroku support for assistance after verifying no API issues are listed on the status page located here.
I got rid if this annoying message on Windows by adding a path element without the spaces, i.e.
C:\Progra~1\PostgreSQL\9.4\data
instead of
“C:\Program Files\PostgreSQL\9.4\data”
I followed the instructions here: http://www.computerhope.com/issues/ch000549.htm, which worked for me if you prefer to go the point-and-click configuration of the PATH variable.
This type of error usually appears in the Windows environment, because if you do not update the PATH after installing Postgresql, heroku pg:psql command does not work.
So you need to update your PATH environment variable to add the bin directory of your Postgres installation. The directory will look like this:
C:\Program Files\PostgreSQL\<VERSION>\bin.
For more information, go to the Heroku in Local setup website:
heroku-postgresql: Local setup
I had the same problem and discovered that Heroku doesn't seem to provision the latest version of PostgreSQL by default. Where the Heroku Getting Started instructions said
heroku addons:create heroku-postgresql:hobby-dev
That provisioned a v10 database for some reason (which you can check by clicking on Heroku Postgres in the Add-ons tab of your dashboard). I deleted that database and provisioned a new database using the --version flag:
heroku addons:create heroku-postgresql:hobby-dev --version 11
As of now, at least, you can find the latest version of Postgres supported by Heroku at this link: https://devcenter.heroku.com/articles/heroku-postgresql#version-support-and-legacy-infrastructure
I'm writing this in early 2019, but according to the PostgreSQL website the next version (12) is "tentatively scheduled" for third quarter of 2019 so if you're reading this in late 2019 potentially the same problem will come up for v12 instead
On Mac you can use the following:
export PATH="/Library/PostgreSQL/12/bin/:$PATH"
The only solution that I found on Windows:
go to advanced system settings
go to environment variables
select Path variable and click Edit
add a new line and enter your bin directory path (C:\Program Files\PostgreSQL<version>\bin) and click ok
restart your terminal
enter your psql command (heroku pg:psql)

What's this error from a simple db unit test of Yii?

root#u1010:/opt/lampp/htdocs/trackstar/protected/tests# phpunit unit/DbTest.php
PHPUnit 3.4.13 by Sebastian Bergmann.
E
Time: 2 seconds, Memory: 5.75Mb
There was 1 error:
1) DbTest::testConnection
CDbException: CDbConnection failed to open the DB connection.
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:275
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:242
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:221
/opt/lampp/htdocs/yii/framework/base/CModule.php:363
/opt/lampp/htdocs/yii/framework/base/CModule.php:86
/opt/lampp/htdocs/trackstar/protected/tests/unit/DbTest.php:6
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
root#u1010:/opt/lampp/htdocs/trackstar/protected/tests#
You should edit the 'db' component declaration in protected/config/test.php
This configuration file is used when you're running your tests.
Check protected/tests/bootstrap.php to see the included files.
Okay. After about half a day of pulling my hair out. This is all I had to do. Hope it helps others. Several simple checks solved this issue. I've got multiple copies of both php and phpunit with different paths. I'm assuming you have your /requirements/index.php checks passed, and your config/main & test files set.
In terminal locate your PHPUnit executable:
which phpunit
Locate your running php executable:
which php
sudo vi path/to/phpunit (the executable)
make sure that the first line referencing the php exectuable is actually the one from step two.
Solved my headache. :)
It could not connect to your database. Either:
Your database connection settings are incorrect.
Your database is not running.
There is a networking misconfiguration.
try:
mysql_connect("127.0.0.1", "root", "123456") or die (mysql_error());
echo "Connected to MySQL";
sometimes the privileges setting for the MySQL server are different for "127.0.0.1" and "localhost". If this is the case, you can do:
mysql> GRANT ALL PRIVILEGES ON trackstar_dev.* TO 'root'#'127.0.0.1';
on your mysql server