server has gone away php mysql connexion error - php

I have a problem when I try to log to my database with php. I have a website in php and I need to use a database so I have file where I try to connect :
$db = new PDO('mysql:host=IP;dbname=DB_Name', 'Username', '********');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
Then I have an error :
Fatal error: Uncaught PDOException: Packets out of order. Expected 0
received 1. Packet size=78 in /var/www/html/index.php:6 Stack trace:
#0 /var/www/html/index.php(6): PDO->__construct() #1 {main} Next PDOException: SQLSTATE[HY000] [2006] MySQL server has gone away in
/var/www/html/index.php:6 Stack trace: #0 /var/www/html/index.php(6):
PDO->__construct() #1 {main} thrown in /var/www/html/index.php on line
6
My database is on a VPS. The database is installed on it with my php code.
I already looked on internet for solution but nothing changed.
Thanks for your help.

if you’re getting the Packets out of order error in the PHP log, there’s an high chance that the issue is due to the fact that there’s an incompatibility between the PHP and MySQL versions you’re using. If upgrading them is not an option, you could try to add the following statement to the PHP script that causes the issue:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

Maybe this may help...
screenshot of "SHOW VARIABLES LIKE '%timeout%'"

Related

Getting fatal error config.php line 14

I am making my forum!
I have sql database and everything that I need to publish to the web (domain etc.)
So after launching my forum to the web I am getting the following error when trying to open my forum:
Fatal error: Uncaught Error: Call to undefined function
mysql_connect() in /storage/ssd5/357/5453357/public_html/config.php:14
Stack trace: #0 /storage/ssd5/357/5453357/public_html/main.php(3):
include() #1 {main} thrown in
/storage/ssd5/357/5453357/public_html/config.php on line 14
I tried everything but nothing worked!
Maybe someone from here can answer my question...
How to fix this?
Try mysqli_connect() instead, ‘mysql’ is deprecated. This is the case for every mysql function, so make sure everything is updated to ‘mysqli’. Hope this helps

Is it possible high availability with Redis Cluster when using it as session handler?

We are trying to use Redis Cluster for storing session data using last version of phpredis, 2.2.5, downloaded from github repository the 19 Juin of 2015, configuring redis as sessions handler in php.ini configuraiton file.
We have 6 instances, three as masters and three as slaves and we have tested that storing and reading session data works.
However if we shutdown any master the following error is shown by our application:
Fatal error: Uncaught exception 'RedisException' with message 'Connection closed' in /users/ets01/lib/php/DEIN/class.PSASession.php:64 Stack trace: #0 /users/ets01/lib/php/DEIN/class.PSASession.php(64): session_start() #1 /users/ets01/lib/php/DEIN/class.PSAPage.php(102): PSASession->__construct() #2 /users/ets01/web/inc/class.APP2Page.php(11): PSAPage->__construct('b', 11) #3 /users/ets01/web/html/index.php(11): APP2Page->__construct() #4 {main} thrown in /users/ets01/lib/php/DEIN/class.PSASession.php on line 64
Fatal error: Uncaught exception 'RedisException' with message 'Connection closed' in [no active file]:0 Stack trace: #0 {main} thrown in [no active file] on line 0
Connection is closed, and cluster does not works as we would like to, we would like that connection is redone to another instance.
Does phpredis driver manage connections to the cluster? Does it provides automatically the chance of getting the value from another cluster instance?
We resolved the problems :-)
At the moment of creating the cluster we have to use the server IP instead of 127.0.0.1
redis-trib.rb create --replicas 1 10.68.10.201:7001 10.68.10.201:7002 10.68.10.201:7003 10.68.10.201:7004 10.68.10.201:7005 10.68.10.201:7006
Now setting and getting values in the cluster from a PHP script works.
Also, for using it as session handler we had to use 5.6 version of, for previous versions we have a "segmentation fault" error.

Cassandra PDO connection PHP

I've got Cassandra working nicely on Debian server however I'm hoping to connect to it from a PHP application.
Currently it seems PDO it the way to go for anything complex as I'm able to use CQL. I'm using the latest forked version of the Apache Cassandra-PDO project.
I'm using the latest Cassandra 2.03 and I can connect to it fine from CQLSH in the terminal.
When I try and connect in PHP using the following code
$db_handle = new PDO("cassandra:host=localhost;port=9160");
I get the following error
Fatal error: Uncaught exception 'PDOException' with message 'CQLSTATE[08006] [8] TTransportException: Transport not open' in /var/www/index.php:9 Stack trace: #0 /var/www/index.php(9): PDO->__construct('cassandra:host=...') #1 {main} thrown in /var/www/index.php on line 9
I've seem a few issues alike on the internet, but no solutions as yet. Hopefully someone can provide some insight into the issue here.
Error 8006 is connection failure. I think you need login and password in PDO Statment like this:
$pdo = new PDO('mysql:host=localhost;dbname=products', 'root', 'root');
Try running 'nodetool status' from the cli to verify the IP address the server is running on.
Then perhaps change localhost to 127.0.0.1 if instead the local host.

PDO extension configuration - I keep getting PDOException "could not find driver" in my PHP application

In a PHP application that I wrote, I keep getting an error that says:
Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message 'exception 'PDOException' with message 'could not find driver' in /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Connection.php:239 Stack trace: #0 /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Connection.php(239): PDO->__construct('mysql:host=loca...', 'diftx_skcin7', 'thePassword', Array) #1 /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Connection.php(101): ActiveRecord\Connection->__construct(Object(stdClass)) #2 /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/ConnectionManager.php(33): ActiveRecord\Connection::instance('mysql://diftx_s...') #3 /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Table.php(103): ActiveRecord\ConnectionManager::get_connection(NULL) #4 /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Tabl in /home/diftx/public_html/dol/sparks/php-activerecord/0.0.1/vendor/php-activerecord/lib/Connection.php on line 241
Based on this message, I did some research about PDO and can't seem to figure out.
Here is a screenshot from my phpinfo() showing PDO information:
When I log into the server via PuTTY and type "php -m" a list of modules appear. In the list is both entries for PDO and pdo_sqlite.
I am somewhat new to server configuration and I simply cannot seem to figure out what I am doing wrong to set this up. Help!
Just like to answer this (I commented the solution). You do not have the required drivers for PDO to work with MySQL. You need to install them before you can use MySQL with PDO.

MongoDB giving weird Connection Error

I'm having a problem with connecting to MongoDB with PHP.
This is my code:
<?php
$server = new Mongo('localhost:27017');
$db = $server->sampleDB;
$coll = $db->sample;
?>
This produces the following error:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'localhost:27017: couldn't get host info for localhost' in /var/www/example/index.php:2 Stack trace: #0 /var/www/example/index.php(2): Mongo->__construct('localhost:27017') #1 {main} thrown in /var/www/wexample/index.php on line 2
Found the problem;
Turns out for some reason Mongo was only listening on 127.0.0.1, not localhost.
So, using $server = new Mongo("mongodb://127.0.0.1:27017");, instead of $server = new Mongo("mongodb://localhost:27017"); fixed the problem :)
Thanks for your help guys,
James
Following the PHP Manual
couldn't get host info for [server]
This indicated that DNS could not
resolve the server address you gave.
This could easily be caused by a typo,
for example, "server" instead of
"$server".
As well, you might want to read the Connecting part of the MongoDB section in PHP doc
EDIT
Have you tried this ?:
$server = new Mongo("mongodb://localhost:27017");

Categories