Mariadb 10 connection from PHP file

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.
Post Reply
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Mariadb 10 connection from PHP file

Post by john.woody »

Last week I updated my TS251+ from qts 4.5.4.1892 to 5.0.0.1986. The update went smoothly and installed MariaDB 5 and everything worked as expected with NAS webserver, php and phpMyAdmin. The NAS is LAN only access, no access from WAN.

This week I installed MariaDB 10. I created a new v10 database (migrating from 5 didn’t work). I followed the instructions
https://www.qnap.com/en/how-to/faq/arti ... phpmyadmin
adding

Code: Select all

port: $cfg['Servers'][$i]['port'] = '3307';
socket: $cfg['Servers'][$i]['socket'] = '/var/run/mariadb10.sock';
to my config.inc.php file. I logged in to phpMyAdmin with root and created my additional user, restored my databases from backups and all was good.

I then went to run a site and got a connection error.

mysqli_real_connect(): (HY000/2002): No such file or directory

I went to control panel, webserver and edited the php.ini file changed

Code: Select all

mysql.default_socket = "/tmp/mysql.sock"
to

Code: Select all

mysql.default_socket = " /var/run/mariadb10.sock "
No luck. Maybe I didn’t restart the webserver. I edited the connection string in my PHP file to:

Code: Select all

$connection=mysqli_connect($myhost,$myuser,$mypass,$mydb,3307, '/var/run/mariadb10.sock');
And the connection worked.

The NAS shutdown overnight, and restarted this morning and on testing my original connection string worked

Code: Select all

$connection=mysqli_connect($myhost,$myuser,$mypass,$mydb);
Job done I thought so I removed MariaDB 5 from the NAS and the connection failed again. By including the port number and path to mariadb10.sock the connection works again.

Have I missed something in the setup which would allow me to remove MariaDB 5 and use the original connection string?

Thanks
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Re: Mariadb 10 connection from PHP file

Post by john.woody »

So to update this and make others aware so they don’t make the same mistake I did. I assumed that by deleting MariaDB5 that the databases stored in there would be destroyed. Not so, neither are the users deleted. So when I re-installed 5 my original connection string worked to the old databases, which were identical to the new ones in 10 as I had backed them up and restored them at that time so there was no difference. Fast forward 3 weeks and I used phpMyAdmin to add a field to one of my databases, updated my php code to save data in that field, tested, but couldn’t get it to save as phpMyAdmin had updated in MariaDB10 and the php files were loading against 5!

Fortunately my backups were all OK backing up against 5 which included my data for the last 3 weeks, so I restored these to version 10, updated my connection strings to use port 3307 and the mariadb10.sock file, as well as updating my backups to use the same. Finally I re-installed MariaDB5, rem’d out the code for phpMyAdmin, logged into it checked it was for 5 and deleted my databases and users there, before un-remming the code and removing 5 from my NAS.

Everything now running on 10, felt like a parallel universe :D
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
Adamsam
First post
Posts: 1
Joined: Thu Feb 09, 2023 3:30 am

Re: Mariadb 10 connection from PHP file

Post by Adamsam »

:DD thanks it's pass perfect in Qnap TS-262 up and running
swissnas
Starting out
Posts: 11
Joined: Wed Dec 14, 2016 7:12 am

Re: Mariadb 10 connection from PHP file

Post by swissnas »

Hi John.Woody

A similar problem has been driving me crazy. I bought a second TS-673A to migrate all my data and my database to larger disks.

I saw only today the info about changing the config.inc.php via SMB in windows - I can open the file in my text editor of choice (notepad++) but it won't let me save the file. I thought maybe I needed to stop the PHPmyadmin service, but then the web folder goes away. How did you manage to edit the config.inc.php file?
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Re: Mariadb 10 connection from PHP file

Post by john.woody »

Hi swissnas

In my case the file was owned by the admin account. I logged into the web interface with this account and edited it with the Text Editor app I had downloaded from the App Store.

You could also edit it from the command line using Putty if you preferred.


Sent from my iPhone using Tapatalk
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
swissnas
Starting out
Posts: 11
Joined: Wed Dec 14, 2016 7:12 am

Re: Mariadb 10 connection from PHP file

Post by swissnas »

Hey John.Woody thanks for your reply.

On this most recent QNAP build, it forced me to create a new admin user at the beginning and the original "admin" account was disabled. From windows using SMB to open the file, i do use this new credential with admin rights - so must be some hang up there.

I just tried the text editor - that was a very simple/clever idea btw - and have permission denied... so it must be a rights issue even though i am logged in on my credentials with admin rights.

Putty is a good suggestion, i'll have to brush up on my Putty skills which aren't so great. I do worry I will have the same permission issues I had via SMB and text editor. So its a rights issue in the end...
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Re: Mariadb 10 connection from PHP file

Post by john.woody »

Correct it’s a rights issue. The built in admin user has edit rights to that file. You could enable the original admin account, make the changes and disable it again.


Sent from my iPhone using Tapatalk
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
swissnas
Starting out
Posts: 11
Joined: Wed Dec 14, 2016 7:12 am

Re: Mariadb 10 connection from PHP file

Post by swissnas »

Thank you - you are amazing. Would buy you a beer (or two) if I could. It should have been more obvious but somehow wasn't... finally after two weeks phpMyAdmin is working again!

Cheers!
Post Reply

Return to “Web Server & Applications (Apache + PHP + MySQL / SQLite)”