Symfony with MSSQL (sqlsrv) results in timeout - php

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.

Related

Docker MariaDB - Column count of mysql.proc is wrong. Expected X, found Y. Created with MariaDB 50731, now running 100508

TL;DR: Trying to fix error before it occurs, not when it happens, as in related questions
First up: I know the error says to run an upgrade script for the DB.
However: I'm running this in Docker. I'm also getting this error after removing the container and the image and creating a new, clean instance.
The database is created by Doctrine, configured for MariaDB 10.5.8 (same version as DB configuration in Docker (see below)).
However, after dumping tables, recreating the db schema and then refreshing the setup in the IDE (PhpStorm) I get this notification:
Error encountered when performing Introspect schema workflow_poc: Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 50731, now running 100508. Please use mariadb-upgrade to fix this error.
Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 50731, now running 100508. Please use mariadb-upgrade to fix this error
From that I read that the schema was created with a MariaDB 5.7 configuration and now we're running MariaDB 10.5. However, nowhere am I using version 5.7 in this setup.
Any ideas on how to fix this before the error appears and without a hack to include the upgrade command somewhere?
Docker config:
db:
image: library/mariadb:10.5.8
volumes:
- "mysql_data:/var/lib/mysql:delegated"
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-project_name}
- MYSQL_DATABASE=${MYSQL_DATABASE:-project_name}
- MYSQL_USER=${MYSQL_USER:-project_name}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-project_name}
- TZ=Europe/Amsterdam
ports:
- "${MYSQL_PORT:-30026}:3306"
Symfony Doctrine config in doctrine.yaml
doctrine:
dbal:
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
driver: 'pdo_mysql'
server_version: 'mariadb-10.5.8'
url: '%env(resolve:DATABASE_URL)%'

How to use mysql instead of mariadb in symfony 5

i think this might be a stupid question for some, but i swear that i can't find the answer by myself actually.
I'm still learning Symfony so please be nice.
Actually i have set up the access to my database in the .env file :
[...]
DATABASE_URL=mysql://root:db_password#127.0.0.1:3308/db_name
[...]
And then i have define the environnement variable in the config/doctrine.yaml :
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: Symfony
user: root
password: null
host: localhost
server_version: '8.0'
driver: pdo_mysql
charset: UTF8
So i run the following command :
> php bin/console doctrine:database:create
But the 'Symfony' database have been created under mariadb.
:( I don't understand why because i have define precisely that i use a 8.0 version and this version is not a mariadb version.
I've also try this :
# .symfony/services.yaml
mydatabase:
# supported versions: 5.7, 8.0
type: oracle-mysql:8.0
disk: 1024
As the symfony documentation saying to do, but it still not working at all.
I have got the following error message as mydatabase is not a symfony services :
C:\Users\vincp\Symfony\charming_tuto>php bin/console doctrine:database:create
In FileLoader.php line 173:
There is no extension able to load the configuration for "mydatabase" (in "C:\Users\vincp\Symfony\charming_tuto\con
fig/services.yaml"). Looked for namespace "mydatabase", found ""framework", "sensio_framework_extra", "twig", "twig
_extra", "web_profiler", "monolog", "debug", "webpack_encore", "doctrine", "doctrine_migrations", "maker"" in C:\Us
ers\vincp\Symfony\charming_tuto\config/services.yaml (which is being imported from "C:\Users\vincp\Symfony\charming
_tuto\src\Kernel.php").
I wanna use mysql because this is the DBMS that i use usually.
(If you think that i should use mariadb instead of mysql i'm open to that, but give me some arguments. I'd be really interseted in)
Maybe it is a server issue. So first, make sure that MySQL is running on your server besides MariaDB (how to do it depends on the type of server you are using).
If yes, it might be a port setting issue: I see that you set the database port to 3308. That is probably the port on which MariaDB is listenning. Try to determine if there is another db running on your server listening to another port (for example 3306 is very often the default MySQL port). To do so, on a Linux server you could try the following command :
netstat -tlnp | grep mysql
If you find only x x.x.x.x:3308 address or so, I bet that MySQL is not running on your server and you only run a MariaDB instance. But if you find addresses on other ports (for example x x.x.x.x:3306) chances are that a MySQL instance is running and listens that other port. If that's the case, you should consequently change the DATABASE_URL in your .env file.

Using MS SQL with Symfony 3

Hi there I need some help with Symfony 3 and a MS SQL Server:
I am using Symfony 3 and want to connect to a MS SQL Server, I've done some research and found out that it is not supported by default but there are some Bundles available to use.
After trying some of them I found one Bundle which partially worked for me (realestateconz/mssql-bundle) but I get an error Message everytime I try to query the DB (I formatted it to be more readable):
Uncaught PHP Exception Doctrine\DBAL\DBALException: An exception occurred while executing
'SELECT
t0.id AS id_1,
t0.username AS username_2
FROM user t0
WHERE t0.username = ?' with params ["testusername"]:
SQLSTATE[HY000]: General error: 156 General SQL Server error:
Check messages from the SQL Server [156] (severity 15) [(null)]
The codeline looks like this
$user = $em->getRepository('AppBundle:User')->findBy(array('username' => $username));
My doctrine and symfony settings looks like this:
#config.yml
doctrine:
dbal:
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
host: "%database_host%"
#port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
#charset: UTF8
#parameters.yml
parameters:
database_host: myserver
database_name: database #without schema
database_user: user
database_password: pw
Port and Charset in config.yml are commented out because I found something here on stackoverflow about doctrine using MySQL when port and charset are defined (can't remember where exactly though).
In the parameters.yml I can not add the schema for the DB (full path to table "User" is database.web.[User]) because it will run in another Error.
The Webserver runs Ubuntu 16.04 with apache2, php5.6 (including the package php5-sybase) and I use freetds to connect to the MSSQL-Server (manually connecting works).
Here are my FreeTDS settings:
[MYSERVER]
host = myserveradress
port = 1433
tds version = 8.0
client charset = UTF-8
text size = 20971520
As far as I understood it, Doctrine generates the wrong SQL-Query from the single line of code (MySQL-Syntax instead of MSSQL-Syntax), so what can I do to fix this? Or is there another way of successfully connecting and querying a MSSQL-Server on Linux with Symfony 3?
I found the solution myself, you need to give Doctrine the exact Table name for your Entities in the Syntax the SQL-Server uses.
For the annotation Format Symfony uses it would look like this:
/** Annotation for your Classfile
* ExampleClass
*
* #ORM\Table(name="[ExampleClass]") <-- Square Brackets for MSSQL
* #ORM\Entity
*/
After Changing the Tablename to MSSQL Format everything worked as expected.

pdo_pgsql could not find driver symfony2 + php problems

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.

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