Symfony4 sqlite3 connection - php

I'm trying to play with Symfony4 and SQlite3.
After:
composer create-project symfony/website-skeleton my-project
and something like LuckyNumber, I try to define DB-connection.
in:
config/packages/doctrine.yaml is:
doctrine:
dbal:
# configure these for your database server
url: '%env(DATABASE_URL)%'
and in .env :
DATABASE_URL="sqlite:///%kernel.project_dir%/db/sqlite3.db3"
Is there any console-command to test connection?
Or maybe:
php bin/console doctrine:query:sql "select * from all_files"
should return resource or something else way to simply test the connection?
Unfortunatelly Google is silent like a grave :-(
How do you test DB connections in Symfony4/Doctrine?
after: php bin/console doctrine:query:sql "select * from all_files"
I got:
In AbstractSQLiteDriver.php line 89:
An exception occurred in driver: could not find driver
In PDOConnection.php line 47:
could not find driver
php7.2-sqlite3-dbgsym is installed and apache2 restarted (but I guess Symfony console do nto use Apache?)...
edit:
after Mike`s prompt, (there wasn't pdo_sqlite for this php ver.) I get:
~/Dokumenty/projects/symfony_mdb/my-project$ php bin/console doctrine:query:sql "select * from all_files"
In AbstractSQLiteDriver.php line 86:
An exception occurred in driver: SQLSTATE[HY000] [14] unable to open database file
In PDOConnection.php line 47:
SQLSTATE[HY000] [14] unable to open database file
but this is new file and none of process using it (I guess). It is possible to open it with SQlite GUI and run query with expected answer...

Yes! I got it!
the problem was in:
config/packages/doctrine.yaml
wrong:
url: '%env(DATABASE_URL)%'
but sholud be:
url: '%env(resolve:DATABASE_URL)%'
Thank you for help!

Related

disable symfony 5 database connection

I have the default config in my symfonu project I have this line at .env file
DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
and I get this error
An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Of course I dont have not isntalled postgres, and I dont need a database for this project, How I cant fix this error I tried to comment the .env file line but I get another error
Commenting the line as L3xpert answer suggests doesn't seem to do the job.
It will throw the error :
Environment variable not found: "DATABASE_URL".
If you don't need Doctrine but you have Website-Skeleton installed, you can remove Doctrine by running this command :
composer remove doctrine/doctrine-bundle doctrine/doctrine-migrations-bundle

Can't generate my database with Doctrine ORM (Could not find driver)

So, I just started using Doctrine, and it's also my first time using Symfony 5.
I used the Maker bundle to generate my first entity, and I completed the DATABASE_URL in my .env, but I can't generate my database with "php bin/console make:migration".
I got these errors:
In AbstractMySQLDriver.php line 106:
An exception occurred in driver: could not find driver
In PDOConnection.php line 31:
could not find driver
In PDOConnection.php line 27:
could not find driver
I searched for a solution, most of the time it's because the corresponding extension is missing... but not in my case !
This is my DATABASE_URL in my .env. I didn't modified anything else.
DATABASE_URL=mysql://myusername:mypassword#localhost:3306/mydatabase?serverVersion=5.7
I'm a complete newbie, and I'm a bit lost.
Can you help me please ?
Thank you !
EDIT: sorry, I totally forgot the most important. Im on Windows 10 with the last version of WAMP, and I installed PHP 7.4.7.
All the extensions are activated, and php -m return them !

Error when trying to create doctrine database with phpMyAdmin

I'm a fresh junior php developer and I'm building my first Symfony project.
When I used the command : php bin/console doctrine:database:create
I get these errors :
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] No such file or directory*
I'm actually using MAMP with default config "db_user" and "db_password"
so I edited the .env file with this following code :
DATABASE_URL=mysql://root:root#localhost:8889/mydbname
I know there is something wrong with my host or port, I saw on other topics that some users using MAMP keep Symfony default values for host and port : DATABASE_URL=mysql://root:root#127.0.0.1:3306/mydbname
Thanks for reading me and trying to help me.
I did more searches and some people are saying that localhost syntax is depreciated and prefer using : 127.0.0.1 instead of localhost.
In my case I checked and used Mamp config 'Connect using an UNIX socket'
So it's now working with :
DATABASE_URL=mysql://root:root#127.0.0.1:8889/mydbname

eZ Platform: Error: "SQLSTATE[HY000] [2002] No such file or directory" when I try to generate GraphQL schema

I've installed eZ Platform on my Mac using the eZ Launchpad docs: https://ezsystems.github.io/launchpad/.
After the installation, I'm able to successfully access the platform and start creating the Content Model.
I would also like to use GraphQL, so I followed the instructions: https://doc.ezplatform.com/en/latest/api/graphql/.
Unfortunately I get an error when I try to generate the schema using the commands:
php bin/console ezplatform:graphql:generate-schema
php bin/console cache:clear
This is the error I get:
In ExceptionConversion.php line 169:
Database error
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] No such file or directory
Here's the app/config/parameters.yml:
# This file is auto-generated during the composer install parameters:
env(SYMFONY_SECRET): ThisEzPlatformTokenIsNotSoSecret_PleaseChangeIt
env(DATABASE_DRIVER): pdo_mysql
env(DATABASE_HOST): localhost
env(DATABASE_PORT): null
env(DATABASE_NAME): ezplatform
env(DATABASE_USER): root
env(DATABASE_PASSWORD): null
env(DATABASE_CHARSET): utf8mb4
env(DATABASE_COLLATION): utf8mb4_unicode_520_ci
env(DATABASE_VERSION): mariadb-10.2.26
Looks like you have executed the composer and symfony commands directly from your host and you have setup the project using launchpad.
Try this instead:
~/ez sfrun ezplatform:graphql:generate-schema
~/ez sfrun cache:clear
With ezlaunchpad your app is running in the docker container so you have to execute all common symfony/ez commands through the ~/ez shell. Executing commands from host can lead to file permission issues as well.

Symfony 4 Limenius workshop

I'm pretty new to coding with php and a friend of mine recommended the Limenius sf4 workshop. However, I'm stuck at the very beginning just to set the database up.
When typing php bin/console doctrine:schema:update --dump-sql into my shell (working on Windows) I get this error messages:
Error thrown while running command "doctrine:schema:update --dump-sql". Message: "An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)"
In AbstractMySQLDriver.php line 113:
An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 50:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
In PDOConnection.php line 46:
SQLSTATE[HY000] [1045] Access denied for user 'db_user'#'localhost' (using password: YES)
I did look for answers online but they all seem to suggest I need to set up my .env file - which I did according to the tutorial in the first step. The webserver runs well, too. I just don't see where I go wrong exactly. Anyone else struggled with this part or may have an idea? Like I said, I'm pretty new to this.
As a test I've tried to create a new db using the command php bin/console doctrine:database:create - same error messages.
Okay, it did work out well once I've realised I need to type in my credentials twice.
This is my .env file (without the comments at top):
DATABASE_URL="mysql://root:root#127.0.0.1:3306/travolta"
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=9c47bf77dd9e746ab12e8fb021e226e1
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL="mysql://root:root#127.0.0.1:3306/travolta"
###< doctrine/doctrine-bundle ###
I did not notice the 2nd last line. I'm so sorry for that! Nevertheless, thanks a lot for helping me out and providing great tipps. It helped me to understand things better.
The database user name or password is incorrect. You can edit this data in the .env file.
Add this line into your .env file:
DATABASE_URL=mysql://{username}:{password}#127.0.0.1:3306/{database_name}
where:
{username} : the username you use to login into phpMyAdmin
{password} : the password you use to login into phpMyAdmin
{database_name} : the database name you would like to use with your Symfony application
Update
According to your comment, if you have not created your database yet, and you feel comfortable with phpMyAdmin, create one:
Then, give the user, sufficient privileges:

Categories