PHP Connection

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.
Locked
MGDike
New here
Posts: 3
Joined: Tue Sep 27, 2022 3:33 am

PHP Connection

Post by MGDike »

Hi All,

I recently bought QNAP with Webserver and SQL Server. I'm still a bitt of a noob and learning.

I have the Webserver running, as well Maria DB running, and able to acces the database by MyPHP in the webserver or by MySQLWorkbench on my local computer. Am running Maria DB 10 over port 3307.

That's great. But strugling with the PHP Script to connect to the database. I think it is connection because status is database connection is ok. The database is filled with records. And if I run my query in WOrkbench it generates 1 record as result.

But nothing is echoo't after the database connection ok. Also simple print statements. Also tried to insert a table same result. No results at all.

Can anyone help?

Thanks in advance

Code: Select all

$dbconnect=mysqli_connect($hostname,$username,$password,$db);

if ($dbconnect->connect_error) {
  die("Database connection failed: " . $dbconnect->connect_error);
}else{ echo "Database connection ok";}

 

 $sql = $dbconnect->query("SELECT Temperature, Humidity, DateTime FROM Home.Kitchen order by DateTime desc Limit 1");
 
 $result = $mysqli->query($sql);
           
         if ($result->num_rows > 0) {
             
                echo "Row";              
           }
lousyfool
Getting the hang of things
Posts: 74
Joined: Tue Apr 20, 2021 1:45 pm

Re: PHP Connection

Post by lousyfool »

This is a generic PHP question, not QNAP-specific or even only QNAP-related.
So, nothing for this forum. No offence, but you've got to make yourself familiar with PHP, and there are tons of other places for this on the Interwebs.
FSC830
Experience counts
Posts: 2043
Joined: Thu Mar 03, 2016 1:11 am

Re: PHP Connection

Post by FSC830 »

In addition: I strongly recommend to do such installations (PHP, MariaDB, ...) in a container or a VM.
If running directly at NAS it happens in past several times that after a firmware or an app update things are not running as before.
So a "simple" QTS update can make the whole installation/configuration unusable!

Furthermore: the PHP packages available for the NAS are often versions behind the latest version.

Regards
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Re: PHP Connection

Post by john.woody »

A search of the forum might have brought you to viewtopic.php?f=32&t=165977 Which would answer your question re the connection string as well as further information.

HTH
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
MGDike
New here
Posts: 3
Joined: Tue Sep 27, 2022 3:33 am

Re: PHP Connection

Post by MGDike »

Thanks for you feedback.

Well John Woody, actual i have seen that post, and already did put it into practise. Because without changing that i couldn't connect with MySql workbench.

I think it's not a regular PHP question, correct me if i'm wrong. Because I tried a lot of thing getting it running several PHP examples.

Some behaviours are diferent on the NAS. For instance the save time, and the time it is visualizes. It takes up to 60seconds to show on the webpage. Now it is almost instant.

Thus i think I did research. And tried some things. And am stuck on connecting. And was hoping from advice from someone who faced the same issue. I think I have read most relevant post or have not used the correct search terms.

I am able to connect to the database, thus in my opinion it has to do with the PHP script, or something in the NAS, ar setting perhaps.

Good advice to put it in a container or VM. I think i will put that idea in practise.
john.woody
Starting out
Posts: 33
Joined: Mon May 27, 2019 10:48 pm

Re: PHP Connection

Post by john.woody »

Did you see the connection string? It references the port and the socket file?


Sent from my iPhone using Tapatalk
Qnap TS251+ 8Gig RAM 2 * 2Gig WD Red HHD RAID1
MGDike
New here
Posts: 3
Joined: Tue Sep 27, 2022 3:33 am

Re: PHP Connection

Post by MGDike »

Yes. Have tried it, but doesn't work.

Code: Select all

$dbconnect=mysqli_connect($hostname,$username,$password,$db, 3307, " /var/run/mariadb10.sock "); 
Locked

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