pdo_pgsql could not find driver symfony2 + php problems - php

I hope you're all good because i'm not, I have some trouble understand how Symfony 2 does work and I too have a extension problem (Could not find driver).
Firstly, php --ini tells me I have to edit my /etc/php.ini file BUT in my SF2 setting, i'm using Php 7.0.0 from MAMP, using /Applications/MAMP/.../php.ini and /Application/MAMP/../bin/php. So I should be using php 7.0.0 from MAMP shouldn't I ?
My web/config.php tells me "Set "xdebug.max_nesting_level" to e.g. "250" in php.ini* to stop Xdebug's infinite recursion protection erroneously throwing a fatal error in your project."
But i don't have any "xdebug.max" in my /etc/php.ini neither in my /Application/Mamp/../php.ini (I still don't know which one is used ... The one from my MAC or from Mamp ? Meh i'm so lost !)
That's my first problem, knowing which php.ini is used and why it appears to be the one in /etc.
Secondly, i've a "Could not find driver" error when i'm trying to generate bundle with php app/console doctrine:database:create
I searched on stackoverflow but all I found is that i had to check my phpinfo(); which says me that pdo_pgsql is enabled, then I went in /etc/php.ini and MAMP/php.ini to find the ";extension : pdo_pgsql" to uncomment but they already were ... So what's wrong ?
I'm trying to use postgreSQL database with SF2 and edited my config.yml and parameters.yml correctly I think. Here is my config.yml :
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
Well if anyone could help it'd be really cool, i don't understand why i have so much trouble understanding SF2.
I absolutly need to know how to use php from MAMP.

Related

Can't create database with Symfony 4.1 : could not find driver

When i do the command php bin/console doctrine:database:create i have these errors :
In AbstractMySQLDriver.php line 126: An exception occurred in
driver: could not find driver
In PDOConnection.php line 50: could not find driver
In PDOConnection.php line 46: could not find driver
config/packages/doctrine.yaml
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
.env
DATABASE_URL=mysql://root:root#127.0.0.1:3306/blogMyProject
My PHP Extensions:
php.ini extensions:
PHP 7.2.7 - MySQL 5.7.11 - Symfony 4.1.4 - I use UwAmp 3.1.0 - I'm on Windows
I don't understand where these errors come from.
This works for my case
symfony 4.2
php 7.3
I enabled
extension=pdo_mysql
in php.ini
in file=> config\packages\doctrine.yaml
dbal:
dbname: database
host: localhost
port: 1234
user: user
password: secret
driver: pdo_mysql
# if the url option is specified, it will override the above config
url: mysql://db_user:db_password#127.0.0.1:3306/db_name
# the DBAL driverClass option
driver_class: App\DBAL\MyDatabaseDriver
RiggsFolly brought the solution :
I have a second php.ini file in UwAmp. The extension pdo_mysql was disabled in bin/php/php-version/php.ini
I have just installed UwAmp 3.1.0 on a Windows 10 machine, and faced this same issue when trying to run the php artisan migrate command on a Laravel app. Here's how I solved it:
Go to bin/php/<php-version>
Make a copy of php_uwamp.ini named php-cli.ini
Open it on a text editor
Replace extension_dir = "{PHPEXTPATH}" by extension_dir = "ext"
Replace zend_extension = "{PHPZENDPATH}/php_xdebug.dll" by extension_dir = "../zend_ext/php_xdebug.dll"
Every time you change PHP Config on UwAmp interface, you must repeat these steps, since the changes are stored on php_uwamp.ini.
in the file php.ini there is the extension extension=pdo_mysql that is disabled. I enabled it and the connection worked.

Symfony with MSSQL (sqlsrv) results in timeout

I am trying to connect Symfony 2.8 to Microsoft SQL Server 2012 by using sqlsrv extension (no pdo sqlsrv, because for php7 - which I am using - there is currently only non pdo).
Trying to run cache clear or access the site in browser results in
"PDO::__construct(): MySQL server has gone away".
When I run the doctrine schema update command, everything works fine and the tables are being generated. Does anyone know how to fix the error? (I don't even know why it says Mysql server gone away when I try to connect on microsoft sql..)
Config:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: sqlsrv
host: testhost
dbname: testdb
user: testuser
password: testpw
mapping_types:
timestamp: string
I am looking for a solution since Friday but was not able to find one. I tried to select some entries from a seperate (non symfony) php skript, and there I got the results and no timeout. Why is Symfony / Doctrine giving me this strange error?
you can try to launch this command for doctrine :
php app/console doctrine:cache:clear-metadata
php app/console doctrine:cache:clear-query
php app/console doctrine:cache:clear-result
Also perhaps upgrade and downgrade your doctrine bundle for restore a correct and initial version of bundle for your project.

Connect Doctrine to a MS SQL Database

Just before i get started, I have been trying to figure this out and have clicked nearly every google link there is and I have read nearly all the other questions on this. But I'm stuck because the bundles that are being suggested for this are out of date.
I am creating a website. Tt is a symfony2 application that is being hosted on Microsoft azure. What I want to do is be able to use doctrine of course to fetch and create users to and from the database.
Now from what I've been reading, to connect to this type of database, I have to use the driver called "PDO_dblib".
I have installed this bundle as it seems to be the only one thats still active, don't quote me on that.
https://github.com/realestateconz/MssqlBundle
Now, I installed this in my vendor folder, is this the correct place to store it? Like so:
Project/
app/
src/
vendor/
realestate/
Of course i added the bundle to the AppKernel like so:
new Realestate\MssqlBundle\RealestateMssqlBundle();
and last but not least here is what i have in my config file:
doctrine:
dbal:
default_connection: default
connections:
default:
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
host: %database_host%
dbname: %database_prefix%%database_name%
user: %database_user%
password: %database_password%
so what im thinking im doing here is telling doctrine to use this driver? dont see what else it could be.
I have also declared my parameters.yml for the connection settings.
PS: I am doing my Dev on Linux Mint!
before i tried the steps of this bundle i also ran throught this websites steps: https://dunglas.fr/2014/01/connection-to-a-ms-sql-server-from-symfony-doctrine-on-mac-or-linux/
But again it was throwing errors, I'll post the errors I get down below!
So for the record I have installed freetds and php5-sybase.
The errors that I am getting are such:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: class_implements(): Class Realestate\MssqlBundle\Driver\PDODlib\Driver does not exist and could not be loaded
and also this when i try to do a:
php app/console doctrine:database:create
(I do have my entity set up)
but i get the following error from the command of create:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_prefix". Did you mean one of these: "database_port", "database_user"?
I have been trying to get this working for the past few days and any help would be fantastic! Any more information needed feel free to ask of course!
According your error code:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_prefix". Did you mean one of these: "database_port", "database_user"?
It seems that you miss configuring the parameter “database_prefix”.
If the tables in your database have the unitized prefix e.g. “core_user”,”core_tasks”… You can configure this parameter in the file parameters.yml if not, you can just remove the parameter % database_prefix % in the dbname line in file config.yml.
Here are my code snippets for your reference:
Config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
parameters.yml:
parameters:
database_host: {your_sql_server_name}.database.windows.net
database_port: 1433
database_name: {database_name}
database_user: {username}
database_password: {password}
And the test query in controller:
$conn = $this->get('database_connection');
$data = $conn->fetchAll('SELECT * FROM Testtable');
var_dump($data);

How to connect to MySQL using SSL on symfony/doctrine

I am trying to connect to MySQL that has SSL enabled.
I am using Symfony2 framework with Doctrine.
In plain PHP, I can achieve this with
$link = mysql_connect("127.0.0.1:3306","test","testpass",true,MYSQL_CLIENT_SSL);
Does anyone know how I can do this in symfony/doctrine?
What is the correct doctrine configuration in config.yml?
UPDATE:
Maybe my question "What is the correct doctrine configuration in config.yml?" is wrong.
So, how do I go about doing this? Where should I start?
Thanks
I have found the answer after a long search and with the help from people from doctrine chat room.
This is the dbal configuration that works on PHP > 5.3.7
It uses three PDO Constants which are not available to PHP prior to 5.3.7
In standard PDO connection:
$conn = new PDO("mysql:host=localhost;port=3307;database=dbname", "user1", "password1",
array(
1010 => '/path/to/certs/priv_key.pem',
1011 => '/path/to/certs/pub_cert.pem',
1012 => '/path/to/certs/ca_cert.pem',
)
);
If trying the above code gives you an error, it is possible that your PHP version is < 5.3.7 then you are unlikely to be able to use PDO with SSL.
Now the solution to the DBAL configuration in config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
password: %database_password%
charset: UTF8
mapping_types:
enum: string
options:
1010 : %priv_key%
1011 : %pub_cert%
1012 : %ca_cert%
default2: # second connection ...
orm:
# orm configuration here ....
Hope this helps anyone who are trying to connect using SSL. As a matter of fact, it is recommended to connect using SSL for all your database connection, if it is possible to do so.
Just wanted to point out that the integer values of the following SSL attribute constants are as follows in PHP 5.4.16:
PDO:MYSQL_ATTR_SSL_KEY: 1007
PDO:MYSQL_ATTR_SSL_CERT: 1008
PDO:MYSQL_ATTR_SSL_CA: 1009
They may vary from one version to another, so best to check these values before plugging them into the DBAL confiugration.

Symfony2 / Doctrine2 can't connect to IBM DB2 database using ibm_db2 client

I'm having an issue with Doctrine2 that seems like a bug but I can't find anyone else on Google with the same problem. I'm hoping somewhere here has experienced this problem and knows how to solve it.
Basically I'm trying to connect to a DB2 database. I prefer to use the ibm_db2 client as it's supposed to be better and faster (than PDO_IBM or PDO_ODBC). I've installed the client and tested it. Everything seems to work there. But when I use Doctrine I get the following error:
Notice: Undefined index: protocol in
...[my folders].../vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/
IBMDB2/DB2Driver.php line 54
So in that file it's looking for $params['protocol'] which seems to have no defaults. So in config.yml I tried this:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
protocol: TCPIP
But when I do that it complains that protocol is an undefined configuration option (and looking through the DependencyInjection stuff it doesn't appear anywhere in there.)
However: if I hard-code TCPIP into the Driver file where the error occurs ... it all works. This is undesirable since it involves changing the vendor supplied file. Has anyone found a way to properly specify the protocol in configuration?
Eventually you're going to run into licensing issues using ibm_db2 as noted here. PDO or ODBC are going to be your only free ways to go. IBM requires DB Connect to use ibm_db2 db2_connect() stuff.

Categories