Errors creating a new database with Doctrine orm symfony - php

i tried creating a new data base using the command:
$ bin/console doctrine:database:create
and I got the following errors:
In ExceptionConverter.php line 91: An exception occurred in the
driver: could not find driver
In Exception.php line 26: could not find driver
In Driver.php line 28: could not find driver
also i tried modifying the database url from:
# DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
to
# DATABASE_URL="mysql://root:#127.0.0.1:3306/SMF?serverVersion=5.7"
I'm using xampp server.

Make sure You have installed all drivers in that machine.
As far as I remember it is: php-pdo and php-pdo_mysql - depending on Your OS.
You need to have a mysql client to make such database.
Basically run this command in Your console:
symfony check:requirements
It will show You what package You are missing to run a Symfony app.
Don't forget to match your MySQL Server version with DNS:
DATABASE_URL="mysql://root:#127.0.0.1:3306/SMF?serverVersion=X.Y"
And lastly, Ouss Ma L'aire Bien mentions, uncomment the DATABASE_URL You want to use and comment out all others.

in your case you should delete the "#"
and if there are other lines staring with DATABASE_URL in your .env file just put "#" in the begining
in other cases, just try your windows cmd

Related

Why can't I view this laravel project?

I am admittedly new to Laravel and back end development but I'm trying to open a Laravel project in my browser and am receiving an error message instead. I'm inheriting this project from a client who was working with another group of developers and they have since gone AWOL so I'm on my own to try to figure out what the issue is here.
The first error messages were:
**Warning:** require(C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
**Fatal error:** require():Failed opening required 'C:\xampp\htdocs\vizzue\bootstrap/../vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in **C:\xampp\htdocs\vizzue\bootstrap\autoload.php** on line **17**
To try to fix that error (from a solution I found on here), I ran composer install in the terminal to try to download the missing files. That switched the previous error messages to Whoops, looks like something went wrong. (Not very helpful).
So then I found more advice on here to get more detailed errors for my problem and was outputted a long list of errors under four separate headings.
Heading 1
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 2
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Heading 3
QueryException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES) (SQL: select * from `sessions` where `id` = hA02gV6ShpNslkw0N8Wrgm8QmyA0ZxoXfCNHsVTK limit 1)
Heading 4
PDOException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
My PHP version is: PHP 7.2.28
My Laravel version is: Laravel Framework 5.4.36
Also, I have created a .env by copying the .env-example file.
EDIT:
I found the database information inside of the database/migrations directory so I actually DO have the database files. I'm still having an error, however. I ran php artisan generate:key and that was fine. But when I ran php artisan migrate I got the following error:
In Connection.php line 647:
could not find driver (SQL: select * from information_schema.tables where ta
ble_schema = homestead and table_name = migrations)
In Connector.php line 68:
could not find driver
first you have change the name of .env.example to .env then configure your database names settings in it. after that run composer install to install your project dependencies. make sure your webserver is up and running
You should configure your .env file to enable laravel access on your database. If you don't have one just copy the .env.example file and rename it to .env.
And then change the following properties:
DB_DATABASE=YOUR_DATABASE_NAME
DB_USERNAME=USER_NAME
DB_PASSWORD=PASSWORD
and then you should run php artisan key:generate to generate a new encryption key
EDIT
For your new problem you should run composer update and then composer require doctrine/dbal
if that does not work
You might need to comment out the following in your php.ini file.
;extension=pdo_mysql.so
As said here
Here is the basic installation process for a laravel project. I'll try to explain each of them so that you'll be able to figure out your mistakes on your own.
Getting the source code
You first need to get the source code of your app . Most of the time it's done via git . For instance , you'll need to type git clone https://github.com/miracuthbert/saas-boilerplate.git yoursaasproject to clone the repository hosted on github here
Install dependencies
Go to the root of the directory of the source code you previously got by typing
cd projectname.
The laravel framework uses composer as its dependencies manager. So you need to install it . (What you already did)
Then, from the root of your project, type the following intructions in the same order :
composer install
composer update
Environment configuration
The environment variables of the laravel framework are managed through a dot env file. An example file named .env.example is generally provided. You'll find it at the root of your project's folder. Assuming you are using a terminal with a bash prompt, type the following command to copy the .env.example to a .env file :
cp .env.example .env
After getting your new .env file, type
php artisan key:generate
to generate secure key in your .env file
Depending on the type of database management system you intend to use, here are some specific configurations to add in your .env file :
MySQL
If you choose MySQL as your DBMS, set the following values in your .env file :
DB_CONNECTION
DB_DATABASE
DB_USERNAME
DB_PASSWORD
homestead is the default DB_USERNAME and localhost is the default database host. Localhost is totally fine for working locally but you need to change your DB_USERNAME to an actual user of your DBMS with the corresponding password.
Sqlite
If you use sqlite, create a new sqlite database by typing :
`touch database/database.sqlite`
After setting up your database, enter the following command to create and populate tables :
php artisan migrate --seed
You may also need to edit other variables in the .env. The official laravel documentation is your best companion for that.
This is to the best of my knowledge what you need to do.
As for the driver error, here are few potential solutions adapted from an answer to a similar problem question asked here :
Be sure to configure the 'default' key in app/config/database.php
For mysql, this would be 'default' => 'mysql',
If you are receiving a [PDOException] could not find driver error, check to see if you have the correct PHP extensions installed. You need pdo_mysql.so and mysql.so installed and enabled. Instructions on how to do this vary between operating systems.
For Windows, the mysql extensions should come pre-downloaded with the official PHP distribution. Just edit your php.ini and uncomment the lines extension=pdo_mysql.so and extension=mysql.so
Also, in php.ini, make sure extension_dir is set to the proper directory. It should be a folder called extensions or ext or similar inside your PHP install directory.
There are other instructions given in the original answer but I'm only recommending those I understand. It was initially written for a postgres dbms.
If there are still problems, take a look at laragon. It's a bit like xamp (that you appear to be using on windows OS), but more powerful and easier to use.
The main backend languages and frameworks can be set up easily in few minutes. That includes php with laravel/symfony, ruby and Ruby on Rails, python and Django.
It allows you to manage multiple versions of the same programming language without any hassle and is fully extendable.
If you're new to Laravel or backend development, and working on the windows operating system, this is a must have.

How to know why OCI8 have different behaviour with php_fpm and php_cli?

I'm currently working on a PHP Symfony 3.4 project and I am connecting with OCI8 to an Oracle BDD.
Also, on the same environment I execute a .php file from command line and I connect to the Oracle bdd from it too.
I am using OID to connect to the database in my symfony app and my .php script.
Here's how I am connecting :
$conn = oci_connect('USERNAME', 'PASSW', 'OID_BDNAME');
Where OID_BDNAME is the database name in OID.
And it's working perfectly fine from the .php script but I can't get it to work within my symfony application, and here's the error :
ORA-12154: TNS:could not resolve the connect identifier specified
Both command line php and php fpm are using /etc/php.ini (I checked with phpinfo(); and $ php --ini)
Do you have an Idea why OCI8 have different behaviour with php_fpm and php_cli, and how to solve this ? Thanks

Doctrine - Error with command database:create or schema:update -f

I need to change some calculations in a CRM but when I've receive the zip file I've unzip it in WAMP, it's use Symfony so I've done the install with composer and update. I'm a beginner with Symfony, Doctrine, ... so I've tried to do the next commands and I've receive some error message I don't know how to resolve it, I've research on the web all days and I've found nothing.
The commands
php bin/console doctrine:schema:update -f
or
php bin/console doctrine:database:create
I've these error messages :
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist
[PDOException]
SQLSTATE[08006] [7] FATAL: role "stats_crm" does not exist
I don't know what do you need for the informations about my environment, I'm using PhpStorm 2016.3.2, PostgreSQL 9.6, PgAdmin 3, phpPgAdmin 5.1, WAMP 3.0.6 and PHP 5.6.25
Thank you, sorry for my bad English and I don't know if you need more information.
The exception message tells you that doctrine can't login to your database host with username stats_crm, because that role does not exist.
To fix that exception, you have to find the right username that can get you in to the database server. Then, open your app/config/parameters.yml, find node named database_user, and update it accordingly (and database_password if necessary).

Symfony Error: [PDOException] SQLSTATE[HY000] [2002] No such file or directory

I just received some open project files form a customer, where I have to make some adjustments. The project is based ons Symfony Framework and in order to get the project running on my machine, I have to set up the symfony workflow.
I already installed all necessary dev dependencies I guess and when I start my app via:
php bin/console server:run
I get following errors: [PDOException] SQLSTATE[HY000] [2002] No such
file or directory
I read couple of threads about this error and most people recommend changing the host from "127.0.0.1" to "localhost" and vice versa.
If i enter "localhost" to be my host, I end up with the error from above.
If I put "127.0.0.1" as my host, I get "connection refused" instead of "No such file or directory"
Make sure your local mysql service is running as well.
Check database configuration in yaml. Make sure the connection to your local mysql is correct.
Run
app/console doctrine:schema:update --force
to create the database and all the tables for the project.
Let us know if anything of this works or does not.
I had the same problem and fixed it by adding
parameters:
#...
database_driver: pdo_mysql
in the app/parameters.yml file.
You should also check if your database_(name|user|password) values are correct.

mongodb service in PHP

I'm trying to connect to mongodb in php.
There's no problem if mongodb is start in shell with mongod command.
new Mongo("mongodb://".$_host.":".$_port,true)
But when i start mongodb server as a service, i can connect with the mongo command, but i cant connect in php.
new Mongo("mongodb://".$_host.":".$_port,true)
Is there any other arguments?
I'm using the last version of mongodb and the last version of php.
Can someone help me?
What are your command line parameters for the MongoDB service? Is it possible that you've specified a different configuration than what you get by default when manually running mongod? What parameters did you use to install MongoDB as a service?
Thanks for your answer and comment, i fix it.
The problem was in the service command line , i use this command
"C:\mongodb\bin\mongod" --bind_ip 127.0.0.1 --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install
instead of
"C:\mongodb\bin\mongod" --bind_ip myIPadress --logpath "C:\data\db\mongodb.log" --logappend --dbpath "C:\data\db" --port 27100 --install
In the php code new Mongo("mongodb://".$_host.":".$_port,true) , $host = myIPadress
That why it was working in command line and not in the php code, it must be the same IPadress, don't use localhost or something like that if you don't use a default new Mongo()

Categories