Hey guys so im trying to connect to my databse that's already created in postgresql (I'm using PGAdmin4 for the user interface of postgresql).
I'm on Symfony CLI version v4.16.3 get three different Timeout.
In details i have a .env file that take the my database url :
DATABASE_URL=postgresql://root:password#127.0.0.1:35583/nd2d?serverVersion=12.3
My doctrice.yaml is set up like this :
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
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 had issue but found a way to fix they were related to pdo drivers for postgresql.
but after i launch the command bin/console make:migration i get those 3 errors:
In AbstractPostgreSQLDriver.php line 73:
An exception occurred in driver: SQLSTATE[08006] [7] timeout expired
In PDOConnection.php line 31:
SQLSTATE[08006] [7] timeout expired
In PDOConnection.php line 27:
SQLSTATE[08006] [7] timeout expired
I avoided working on heavyn program with PHP or any framework related to it but this time i don't have a choice, soo much configuration i cant take it anymore, been on this for soo many hours now. What am i missing.
Thank you :)
Error came from listening on the wrong port, i was listening to the port 35583, which is the port that PgAdmin is showed on the web browse.
DATABASE_URL=postgresql://root:password#127.0.0.1:35583/nd2d?serverVersion=12.3
The port i should have been listening to is the default postgresql port of 5432
Related
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 am using Symfony 4.0.3 and I need connect to Oracle DB. I follow this instructions:
https://symfony.com/doc/current/doctrine.html
my .env file
DATABASE_URL=oci8://user:pwd#xxx.xxx.xxx.xxx:1521/something
host address is from tnsnames.ora -> HOST, something is from tnsnames.ora -> SERVICE_NAME
And after running command:
php bin/console doctrine:database:create
I get this error:
C:\Apache24\htdocs\myapp>
2018-01-25T12:58:47+00:00 [error] Error thrown while running command
"doctrine:d
atabase:create". Message: "Notice: Undefined index: dbname"
In AbstractOracleDriver.php line 125:
Notice: Undefined index: dbname
I am able to connect to DB by plain PHP, but through Symfony not. dbname is something from my connect url at .env file. This is set from tnsnames.ora.
It looks like the dbname parameter is not picked up from your environment variable / DBAL url.
To solve this quickly just use explicit configuration instead of URL for doctrine DBAL's configuration.
The full reference configuration can be found in the symfony documentation -
Doctrine DBAL Reference Configuration
The documentation for the Doctrine DBAL Oracle configuration can be found here.
config/packages/doctrine.yaml:
doctrine:
# [..]
dbal:
default_connection: oracle_db_1
connections:
oracle_db_1:
driver: 'oci8' # ... or 'pdo_oci'
dbname: '<dbname>'
host: '<host>'
port: '<port>'
user: '<user>'
password: '<password>'
If that works replace dbname, host, port etc. with container parameters (i.e. '%env(DATABASE_NAME)%') read from environment variables and add those to your .env file.
doctrine.yaml edited like this:
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:
default_connection: default
connections:
default:
driver: 'oci8' # ... or 'pdo_oci'
dbname: 'dbname'
host: 'xxx.xxx.xxx.xxx'
port: '1521'
user: 'user'
password: 'pwd'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
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
after command
php bin/console doctrine:database:create
I have same error.
2018-01-26T06:23:31+00:00 [error] Error thrown while running command "doctrine:d
atabase:create". Message: "Notice: Undefined index: dbname"
In AbstractOracleDriver.php line 125:
Notice: Undefined index: dbname
my dbname is same as I have in SQL Developer in SID item.
There is a bug in doctrine/dbal version <= 2.8.0.
Upgrade to doctrine/dbal to version 2.9.0 and it should start to work.
Here is the github pull request solving this issue:
https://github.com/doctrine/dbal/pull/3297
If you use the SERVICE_NAME for your connection, you can define the DATABASE_URL like this:
DATABASE_URL=oci8://user:pw#x.x.x.x:1521/?service=1&servicename=something&charset=AL32UTF8
I have an existing entity in a Symfony3 project that I am trying to add an entity manager to. My doctrine.yml file looks like this
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
lego:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
lego:
connection: lego
mappings:
AppBundle: ~
However anytime I try to access this entity manager through php bin/console doctrine:database:create --connection=lego
, it says the manager does not exist! I'm not sure if I'm missing a step - the only thing I've done to create the manager is to make the yml file.
It doesn't show up when I run bin/console debug:container.
Grateful for any help!
1) You are using the same schema name (database name) on the same host in two different entity managers without schema_filters. This means that when you do an update to one of the entity managers it will attempt to delete the data of the other entity manager.
2) You are asking about a entity manager but in the command you are passing a connection.
3) Run php bin/console debug:container | grep doctrine
This will give you all the doctrine services. Update your question accordingly.
4) Provide the exact command and exact error you get so we can track it down to the origin
5) For a more information run the command in verbose mode adding -v at the end
6) Are you importing your doctrine.yml in your config.yml ?
I am using MongoDB Atlas cloud services with my Symfony 3 application and I am having lots of warnings in my PHP logs saying MongoClient::__construct(): SSL: Connection reset by peer. Even though I have warnings some times, I can connect successfully and read/write to the server.
I use Doctrine ODM which uses MongoClient for connecting to the server. I have configured the replicaSet according to MongoDB Atlas configuration.
When I look at MongoDB logs, I do not see any strange thing that appears to be linked to my issue.
Here is my connection string: mongodb://<USERNAME>:<PASSWORD>#datalake-shard-00-00-lnres.mongodb.net:27017,datalake-shard-00-01-lnres.mongodb.net:27017,datalake-shard-00-02-lnres.mongodb.net:27017/test?ssl=true&replicaSet=DataLake-shard-0&authSource=admin
Here is my Doctrine ODM config
doctrine_mongodb:
connections:
default:
server: "mongodb://<USERNAME>:<PASSWORD>#datalake-shard-00-00-lnres.mongodb.net:27017,datalake-shard-00-01-lnres.mongodb.net:27017,datalake-shard-00-02-lnres.mongodb.net:27017/test?ssl=true&replicaSet=DataLake-shard-0&authSource=admin"
options:
authMechanism: SCRAM-SHA-1
authSource: admin
connect: true
ssl: true
password: "<PASSWORD>"
username: "<USERNAME>"
readPreference: secondaryPreferred
replicaSet: "DataLake-shard-0"
default_database: "test"
document_managers:
default:
auto_mapping: true
retry_connect: 4
retry_query: 4
I'm testing Memcached on my Symfony2 application
I set it to cache doctrine's queries, results and metadata:
orm:
entity_managers:
default:
metadata_cache_driver:
type: service
id: doctrine.cache.memcache2
query_cache_driver:
type: service
id: doctrine.cache.memcache2
result_cache_driver:
type: service
id: doctrine.cache.memcache2
services:
memcache:
class: Memcache
calls:
- [ addserver, [ 'localhost', 11211 ]]
doctrine.cache.memcache2:
class: Doctrine\Common\Cache\MemcacheCache
calls:
- [setMemcache, [#memcache]]
Until now, everything works fine.
I was wondering how does doctrine behaves if the Memcached server goes down. As far as I could see, the application breaks. In dev mode I get the following message:
Notice: MemcachePool::get(): Server localhost (tcp 11211, udp 0) failed with: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
(10060)
500 Internal Server Error - ContextErrorException
In production mode I'm also presented with an http 500.
Is there a way to tell doctrine to bypass/ignore the Memcached server and go directly to the database, instead of returning 500s?
You can use The Second Level Cache available in doctrine/orm 2.5
see:
http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html
The idea to keep you default options for orm and add a memcache as second level cache:
orm:
entity_managers:
default:
auto_mapping: true
second_level_cache:
region_cache_driver:
type: service
id: doctrine.cache.memcache2
enabled: true
regions:
region_name:
cache_driver:
type: service
id: doctrine.cache.memcache2
When turned on, entities will be first searched in cache and if they are not found, a database query will be fired and then the entity result will be stored in a cache provider.