The display width of the device is not suitable for displaying this website.
Please turn your device into landscape mode.
<< Back to categories index < Back to threads index
Connection to MySQL server has failed
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 10th 2018, 0:36; Edited by raoul on Apr 19th 2018, 6:41
I tried your forum to post a message about an installation faillure, but it times out.
Very frustrating.
An email address?
thanks.

Edition: title
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 10th 2018, 6:44
Hello,

I increased the validity of the sessions from 10 to 15 minutes. Try again or have a look at my profile. Please use the forum in priority.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 10th 2018, 23:56
Hi,
Thank you.
I get a connection fail on ../gnew/includes/mysql.php on line 29.
The error message is:
Connection to MySQL server has failed.

My system is CentOS 7 with Mysql ver 5.7.21and php ver 7.1.15.

Is this because of php ver 7 [the script needs to be updated for mysqli] or is it because something is missing/not configured?
Help please.
Thanks.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 11th 2018, 7:54
Hello,

Are you sure to use the right host name, user and password for MySQL ?

Are you getting any error in the Apache and/or PHP error logs ?

On my development environment I'm using MySQL 5.7 with PHP 5.6 or PHP 7.0. I don't think PHP is the problem.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 12th 2018, 1:32
Hi,
Thank you. The Mysql credentials are O.K.
Now, a bit further and one more problem:
1. I checked/double-checked the permissions and also modified the SELinux to allow read/write.
Now, the script is 90% working but I still get the first warning that I told you about and also another warning as well:

Warning: Declaration of mysql::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in /gnew/includes/mysql.php on line 29

Warning: session_start(): Failed to read session data: user (path: /var/lib/php/mod_php/session) in /gnew/includes/sessions.php on line 116

About the second warning: I have given 777 rights to those folders. I do not know what else is the cause of this error.

2. The 'Administration' link in the side panel also gives me this error and does not go into the admin side:
You are not allowed to access to the administration section.
I think this is a session-related problem. But, as I do not know what else to do to allow access to var/lib/php/mod_php/session, then I am stuck.

Help/ideas?
thanks again.

raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 12th 2018, 7:53; Edited by raoul on Apr 12th 2018, 7:56
Hello,

Is php_mysqli extension enabled in the PHP config ? If MySQL is not working correctly then sessions will also not work correctly since they are using the database handler. And you won't be able to log in.

You could try to use SQLite with the php_sqlite3 extension enabled in PHP. To check that it's a PHP/MySQL related problem and not a permission problem.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 12th 2018, 18:38
Hi,
No joy, I'm afraid.
mysqli is installed and working, no problem.
sqlite3 is also installed.
If I re-install with mysqli, then I get the first two errors. If I manually alter the access settings in includes/mysql.php, then I get a blank page after stage 3.
If I switch to sqlite, then warning #1 obviously goes away, but still end up with the other two errors: session problem on line 116 and no admin access.

What next?
Kind regards.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 13th 2018, 22:24
Hello,

I'm sorry, I've no idea what it could be. Perhaps you could post the output of:

Code:1<?php
2
3phpinfo
();
4
5
?>


Do you always try with a fresh install ? The file includes/config.php fills up during the installation step. You need to replace it with an empty one each time you restart a new installation.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 15th 2018, 15:59
Hi there,
I have written the content of the phpinfo to an html file.
Shall I send you you an email with the file attached? Is that O.K. as it is too large to just post it here.
Also, as per fresh install, the answer is no. I did not know about replacing the config file with a new one. I shall do that next time.
Thanks again.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 15th 2018, 20:09
Hello,

Yes, you can send me the file by email if you want.

Good luck!
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 16th 2018, 8:20
Hello,

I've received your file, thanks.

I don't see any major differences... except cookies. There's no HTTP_COOKIE in Apache Environment and no Cookie in HTTP Headers Information.

Does you browser allow cookies?

Also refer to the documentation.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 17th 2018, 2:47
Hi,
Thank you.
Yes, In Firefox, I have session cookies allowed. However, I have tried it with Konquerer as well.
I tried for one last time a clean installation. Now, I am back to square one: Cannot connect to MySql...
I have checked permissions, disabled SELinux and manually entered values in mysql.php as well. Dead end.
I am trying to find a good, clean php-based script so that I could learn the routines and do rapid application development. It is for this reason that I am giving you a headache. Sorry about that.
Kind regards.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 17th 2018, 8:41
Hello,

Ok. In includes/mysql.php file, line 56, find :

Code:exit('Connection to MySQL server has failed.');

and replace with:

Code:1// exit('Connection to MySQL server has failed.');
2
printf("Connection to MySQL server has failed: %s\n"$this->connect_error);
3exit();


To see which error is reported.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 17th 2018, 15:29
Hi there,
Thank you. I should have thought of that, shouldn't I? Sorry about that.
The reason for the error was that I have given the ip number as the host name. When I changed it to 'localhost' it went ahead and finished the installation. However, I have now ended up as before: detailed in my second posting on Thu, Apr 12th 2018, 1:32 am.

Session cookies are present; PHSESSID cookie is set by gnew.xyz.

I have also changed the session save path to /tmp but no change. the second error is still there.

Apart from the above two errors, I have noticed two more anomalies:
1. If I press the 'Administrator' button, I get that error that says please go away. But the anonymous user count in the footer increases by one.; and
2. If I press 'Register' the captcha is not loaded/generated. It just outputs the word CAPTCHA instead of the image.

So, the ball is now back in your court.
Sorry about that.
thanks again
kind regards.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 17th 2018, 16:11
:-/

Ok. So the problem with MySQL connection is resolved :-)

I have also changed the session save path to /tmp but no change.

This is useless. As I've already said sessions are using the database handler. They are stored inside the database.

Admin access denied and captcha not generated are both related to a session problem. You won't be able to log in if cookies are disabled and the session is bad. The captcha will not be generated if session is not initialized.

My advice: delete everything (the files and database tables). Close the browser and double check that cookies are really working. Make sure the Site URL parameter is good (normally localhost in your case). Increase Sessions validity if needed.
Enrique55
Registered: on Apr 10th 2018, 0:25
Posts: 8

./../images/avatars/empty.png
^ on Apr 17th 2018, 23:48
Hi there,
Thank you. I did all that but still no joy. All the warnings/problems still exist. Now:

1. Is Warning #1 a mysqli-related?
2. Is Warning #2 a php7.1-related?

On Warning #2, I found this Stackoverflow posting. Does it help?

https://stackoverflow.com/questions/41540302/failed-to-read-session-data-on-php7-1

3. How about a PDO version of the script?

4. How about some dummy data to populate the tables?
Thanks again.
Kind regards.
raoul
Registered: on Apr 1st 2013, 15:08
Posts: 16

./../images/avatars/raoul.png
^ on Apr 18th 2018, 8:21
Hello,

I already wrote:Admin access denied and captcha not generated are both related to a session problem.

My last chance:

In includes/sessions.php file line 115, before:

Code:session_set_save_handler('sess_open''sess_close''sess_read''sess_write''sess_destroy''sess_gc');

add this line:

Code:session_set_cookie_params(0'/''localhost');

If HTML language is enabled and you want to use it, please check start and end tags.

HTML language is disabled