I'm on Symfony and I can't connect to a Oracle database, but I don't know why. Maybe you can help me a little.
Here my doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
url: '%env(DATABASE_URL)%'
server_version: '5.7'
charset: utf8mb4
test:
# configure these for your database server
url: '%env(DATABASE_TEST_URL)%'
driver: 'oci8'
server_version: ~
charset: utf8mb4
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
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
test:
connection: test
mappings:
test:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Test'
prefix: 'App\Entity\Test'
alias: Test
My .env file with 2 database:
DATABASE_URL=mysql://xxx:xxx#mysql:3306/pivot
DATABASE_TEST_URL=//user:owd#host:port/dbname
And here my controller
public function xxx() {
$entityManager = $this->getDoctrine()->getConnection('test');
$sql = 'SELECT * FROM xxx.O2_ADRESSE WHERE ROWNUM = 1';
$stmt = $entityManager->prepare($sql);
$stmt->execute();
dump($stmt->fetchAll());
}
I get the following error :
An exception occurred in driver: ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
Any help on what im doing wrong?
Are you sure that the db is running?
You can check it via sqlplus, eg:
sqlplus user:password#mysql:3306/pivot
Can you update DATABASE_URL and try?
to use oracle: DATABASE_URL="oci8://db_user:db_password#127.0.0.1:1521/db_name"
https://symfony.com/doc/current/doctrine.html
https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html#oracle-db
Related
I'm trying to use multiple entity managers as described here.
Example code in controller where $shop variable holds the name of the manager:
$rp = new RemoteProduct();
$rp->setProducts(array(2000,2001,2002));
$em = $this->getDoctrine()->getManager($shop);
$em->persist($rp);
$em->flush();
$repo = $em->getRepository(RemoteProduct::class, $shop);
$repo->findAll();
Generates queries to both managers. Flush as a transaction in the correct DB, but select queries are executed in the default DB instead. Any ideas?
doctrine:
dbal:
default_connection: shop1
connections:
shop1:
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
enum: string
store2:
url: '%env(resolve:DATABASE_URL_STORE)%'
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: true
default_entity_manager: shop1
entity_managers:
shop1:
connection: shop1
mappings:
shop1:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: shop1
store2:
connection: store2
mappings:
store2:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: store2
It happens that big fat warning at the end of the documentation was ignored by me.
Do not extend repository class from ServiceEntityRepository
In order to fix this situation, extend EntityRepository instead and no longer rely on autowiring:
This question already has answers here:
How to set namespace and item expiration for a symfony5 redis cachepool
(2 answers)
Closed last month.
I would like to set a default cache lifetime / timeout for doctrine caches in my different environments.
php bin/console config:dump-reference doctrine
shows only options to set the lifetime quite deep down in the advanced configuration in the entity manager regions, where I rather would not mess around. I cannot believe that there is no place to set a general value for db result caching.
Is there really no option to set the default timeout for the cache in a config file?
currrent config/test/doctrine.yaml:
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
I've did it like this...
framework:
cache:
default_memcached_provider: 'memcached://localhost:...'
pools:
doctrine.result_cache_pool:
adapter: cache.adapter.memcached
public: false
default_lifetime: 86400
In config/packages/prod/doctrine.yaml
Need to change to:
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_pool
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
I tried many ways to generate Jhipster app with oracle as DEV_DATABASE_TYPE.
still not succeed and i can't find the steps to follow.
Tested with Jhipster 11g2 and 12c2, non of it worked.
Steps i followed :
Generate and app using JDL fil : app.jdl
application {
config {
applicationType monolith,
baseName jhipsterSampleApplication,
packageName io.company.crud,
authenticationType jwt,
databaseType sql,
prodDatabaseType oracle,
devDatabaseType oracle,
buildTool maven,
searchEngine false,
testFrameworks [gatling, protractor],
clientFramework angularX,
clientTheme Litera,
clientThemeVariant Light,
enableTranslation true,
nativeLanguage en,
languages [ en, fr ]
}
entities *
}
Then i update these files : application-dev.yml and pom.xml
spring:
profiles: dev
datasource:
driverClassName: oracle.jdbc.OracleDriver
dataSourceClassName: oracle.jdbc.pool.OracleDataSource
url: jdbc:oracle:thin:#localhost:1521:orcl
username: rest_test
password: rest_test
jpa:
database-platform: org.hibernate.dialect.Oracle10gDialect
database: ORACLE
openInView: false
show_sql: true
generate-ddl: false
hibernate:
ddl-auto: none
naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
properties:
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
I tried to delete this line from app.jdl :
prodDatabaseType oracle,
and i got an error saying : Only 'h2Memory', 'h2Disk', 'mysql' are allowed as devDatabaseType
Does anyone have a clear process to follow, in order to generate an app with Oracle DB ?
Thank you
This question was resolved here : stackoverflow.com/questions/60640151/jhipster-and-oracle-11gr2 thank you all
Is there a simple way to debug why Doctrine is not connecting to MySQL?
config.yml has:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
and parameters.yml seems to have the correct connection information in it. E.g.
parameters:
database_host: 127.0.0.1
database_port: null
database_name: <my database name>
database_user: <my database user>
database_password: <my database password>
However this piece of code still echoes out "Not connected".
$cnx = $this->getDoctrine()->getConnection();
if ($cnx->isConnected()){
echo "Connected";
}
else {
echo "Not connected";
}
and I'm not getting any errors returned.
Any suggestions?
This works:
$em = $this->getDoctrine()->getManager();
$em->getConnection()->connect();
$connected = $em->getConnection()->isConnected();
$connected will be true to indicate it is connected.
The connect() establishes the connection, and then isConnected() returns a boolean to tell if it is connected.
I'm trying to get on with the Symblog Tutorial for Symfony2 (http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html)
After I created my databse with php app/console doctrine:database:create I dont have acces to localhost/MAMP/ anymore?! This is the Error Message "Error: Could not connect to MySQL server!"
Can anyone help me?
Thats my config.yml
Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
unix_socket: /var/mysql/mysql.sock
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
Thats my parameters.ini
[parameters]
database_driver="pdo_mysql"
database_host="localhost"
database_port="3306"
database_name="symfony"
database_user="root"
database_password=""
The default port for MAMP server should be 8889 while you are using 3306, the error could be that.
My parameters
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: symfony_blog
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: 7f03537e81f981683bc773b9ec7113ab5861adec
database_path: null