I have a problem connecting from eZPlatform 3.0 (based on Symfony 5) to the Azure MySQL database.
I get the error:
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL
options and retry.
Configuration is as follows:
doctrine:
dbal:
# configure these for your database server
driver: '%database_driver%'
charset: '%database_charset%'
default_table_options:
charset: '%database_charset%'
collate: '%database_collation%'
url: '%env(resolve:DATABASE_URL)%'
options:
!php/const:PDO::MYSQL_ATTR_SSL_CA: '%ca_cert%'
!php/const:PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT : false
Strange thing is that this happens when I visit the route /admin, on homepage I don't get that exception.
Related
I'm trying to connect to my aws rds database with symfony. But I constantly get an error: An exception occurred in driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.". My security groups are open to all ports and here are my settings.
//services.yaml
parameters:
database_driver: pdo_mysql
database_host: '%env(RDS_HOSTNAME)%'
database_port: '%env(RDS_PORT)%'
database_name: '%env(RDS_DB_NAME)%'
database_user: '%env(RDS_USERNAME)%'
database_password: '%env(RDS_PASSWORD)%'
//doctrine.yaml
doctrine:
dbal:
# if the url option is specified, it will override the above config
default_connection: default
connections:
default:
dbname: '%env(RDS_DB_NAME)%'
user: '%env(RDS_USERNAME)%'
password: '%env(RDS_PASSWORD)%'
host: '%env(RDS_HOSTNAME)%'
driver: 'pdo_mysql'
port: 3306
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
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
In .env you are the correct variables.
If someone has a fix, please provide it to me :)
I found the problem.
Currently, I'm a student and living in a student dorm. My dorm network is blocking the connection with an outside MySql server so that's why I repeatedly get this error.
The solution would be to use a non-public source of the internet or try to share internet from some other device. You could also use a VPN (make sure to test first because with some of them the same error ocurrs).
When launching my web app I get a 500 error. The prod.log shows a connection error to the database, and just below that there is a cache.WARNING: Failed to save key in the /var/www/project/var/cache folder. (Not sure if they are related.)
The error says getaddrinfo failed: Temporary failure in name resolution at /var/www/etc.
I've tried changing the configuration of the db connection string from localhost to 127.0.0.1 to the actual IP address and not seeing a difference.
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
.env
DATABASE_URL=mysql://username:password#127.0.0.1:3306/atlas
I'm expecting the configuration to correctly identify the localhost or local ip address and connect to the db.
The issue with db error was resolved by created a new repo for the web app and set to run using prod environment variables from the beginning. I can only assume the old files held on to some configuration somewhere that was causing the issue. With the failure to save key error I resolved that by giving read/write permissions to the projects var folder. The Syfmony docs only suggest doing this to the var/log directory however it had problems writing to other var/ directories as well.
I'm setting up a new project on Symfony 4.2, and I'm trying to connect to Microsoft SQL Server as database, so I have the following files:
/config/packages/doctrine.yaml:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_sqlsrv'
#server_version: '5.7'
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
/.env part:
###> 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=mssql://sa:root#DESKTOP-A9GIM4A\ISTANZA:1433/linkontro
###< doctrine/doctrine-bundle ###
MSSQL Service is running correctly, but when I try to run on CLI:
php bin/console doctrine:schema:validate
it returns this error:
Mapping
-------
[OK] The mapping files are correct.
Database
--------
In PDOConnection.php line 31:
SQLSTATE[08001]: [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
In PDOConnection.php line 27:
SQLSTATE[08001]: [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
doctrine:schema:validate [--skip-mapping] [--skip-sync] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
Any clue of what's going on?
I tried to write a simple PHP script to check the connection, and it worked.
So credentials are correct, MSSQL Service is on, but the only one who can't connect is Symfony.
From the error description: the php-initiated connection is refused by the MS SQL server. This could mean:
there is no server listening on the address/port you are trying to connect to. Maybe DATABASE_URL is not set correctly and doctrine is trying to connect to the driver's default (i.e. localhost:1433)
the server you are connecting to (or some firewall in between you and the server) is refusing connections - but this is less likely.
Try to add a -v or -vv to the command for more verbosity.
Because of the \ and some unknown reasons,
I find it easear to have it to work using the yaml configuration like following.
doctrine:
dbal:
#url: '%env(resolve:DATABASE_URL)%'
#driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
driver: 'pdo_sqlsrv'
host: DESKTOP-A9GIM4A\ISTANZA
dbname: linkontro
user: sa
password: root
I have been using Symfony with Doctrine for some time, and up until now was able to configure Doctrine to connect to several databases on the same server (IP), through the config.yml.
But now I have a different scenario.
I am working on a case, that has multiple projects running on different IP adresses. I can connect with the database that runs locally on the machine that also hosts the main application, but now I need to connect to another database that's hosted on another server. So, to lay out this case:
Server Alpha. IP: 193.15.15.15, database name: "Foo"
Server Beta. IP: 193.15.15.16, database name: "Bar"
I have defined the user and password for each of these databases in my parameters.yml, so that is no biggie. I just would like to know if it's possible to connect to the (locally hosted) database on server Beta, while the application is on server Alpha.
Thanks in advance!
You should configure multiple entity managers and connections
On the file config.yml :
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: '193.15.15.15'
port: '%port_parameter_for_foo%'
dbname: 'Foo'
user: '%user_parameter_for_foo%'
password: '%pass_parameter_for_foo%'
charset: UTF8
customer:
driver: pdo_mysql
host: '193.15.15.16'
port: '%port_parameter_for_bar%'
dbname: 'Bar'
user: '%user_parameter_for_bar%'
password: '%pass_parameter_for_bar%'
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
BundleOnAlpha: ~
customer:
connection: beta
mappings:
BundleOnBeta: ~
The doc is more complete:
https://symfony.com/doc/3.4/doctrine/multiple_entity_managers.html
I'm trying to connect to my database in SQL Server 2000, but i get an error
could not find driver
when i'm using pdo_sqlsrv.
But if i use sqlsrv i get an error
Attempted to call function "sqlsrv_configure" from namespace
"Doctrine\DBAL\Driver\SQLSrv".
Here is my config.yml
config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
host: "%database_host%"
driver: pdo_mysql
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
connection2:
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
host: "%database_host2%"
driver: pdo_sqlsrv
#driver: sqlsrv i've also tried this
#charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Does anybody know why i'm getting these errors?
If the function sqlsrv_configure can't be found, then the sqlsrv extension isn't installed. It can be found on the official Microsoft repository here.
You can check if you've installed the extension by running the command php -m in your terminal. Note that if you're running Symfony on a standalone server (eg MAMP, XAMP, or anything else that uses a non-CLI version of PHP) then the extensions used by the CLI and the standalone server may differ.
You can test this by going to the profiler in Symfony (/_profiler by default) and clicking on the "View full PHP configuration" link under the Configuration menu item. This will open the phpinfo() screen. Look for either the sqlsrv or pdo_sqlsrv extensions there.
EDIT
Looking at the Doctrine docs again, it seems that pdo_sqlsrv causes problems. Doctrine recommends using sqlsrv.
pdo_sqlsrv: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.
(Emphasis not mine)
Can you try:
driver: pdo_sqlsrv
database_port: 1433
Not sure if that will work, but try it.