4

I have an older Synology device (DSM v5.2-5967 Update 4, phpmyadmin v4.4.7-0103) that has some local websites with working php pages. I want to migrate this over to my new Synology device (DSM V6.1.3-15152 Update 1, phpmyadmin v4.6.6-0172). When installing the new version of phpmyadmin from Package Center, I am required to download Maria DB and PHP 5.6 as well, whereas this is not a requirement in DSM 5. Further, DSM 6 now supports options in Web Station, where I can configure the http back-end server and PHP version. I set this to 5.6, the one installed alongside phpmyadmin.

Here is the code that used to work for me in the old DSM:

<?php
define ("DB_HOST", "localhost"); // Your database host name
define ("DB_USER", "root"); // Your database user
define ("DB_PASS", ""); // Your database password
define ("DB_NAME", "groceries"); // Your database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
?>

This code now returns "Couldn't make connection". Other sites that don't handle this return a 500 server error. I've tried replacing localhost with the name of the Synology device, to no avail. PHP files themselves work fine but I cannot connect to a database. I cannot see the control panel for Maria DB anywhere, so I don't know if I'm missing any settings. This is a new device, with a fresh install of packages so I haven't even changed the root password yet.

I even tried installing Apache 2.4 from Package Center, and setting that as the back-end server in the new Web Station settings, and rebooting the NAS. But phpyadmin still shows "nginx/1.11.10" as the web server. For reference, my old NAS shows Apache under web server, but I don't have the Apache package installed.

I'm at a loss. Has anyone tried to connect to a mysql database using Synology DSM 6 and lived to tell the tale?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Freakishly
  • 1,533
  • 5
  • 32
  • 61
  • 3
    **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) which has been **removed** entirely from the latest version of PHP. You should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Aug 16 '17 at 08:55
  • 1
    While you shouldn't really be using the mysql_* functions, as others have noted, you should at least temporarily print out the value of `mysql_error()` on failure: that will be the actual error message from the connection failure, and might shed some light on what's going on. (Also, does phpMyAdmin work? If so, what username, host and password are you using to connect in there? The server details should be in the Database Server box, top right of the phpMyAdmin home screen...) – Matt Gibson Aug 16 '17 at 09:04
  • Thank you, and my apologies for not knowing that mysql_* functions had been deprecated. I was able to connect to the mysql db, but it looks like php is on port 3306, and mysql is on 3307. Because of this, I have to use "localhost:3307" as the DB_HOST instead of plain old "localhost". How can I force mysql to move to 3306, or PHP to 3307? – Freakishly Aug 16 '17 at 16:37

4 Answers4

2

I am using DSM6 with DS716+, and following code is work for me. There are too many cause to reach the connection issue. Such as the extension does not enable, etc. Please use phpinfo() to verify before any other steps. Try to use mysqli extension instead of mysql, attach an example code for you:

<?php
$mysqli = new mysqli("localhost", "dbuser", "dbpassword", "dbname");

$query = "SHOW TABLES";
if ($result = $mysqli->query($query)) {
    while ($row = $result->fetch_row()) {
        printf("%s <br />\n", $row[0]);
    }
    $result->close();
}

$mysqli->close();

?>

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
Allen Chak
  • 1,802
  • 1
  • 10
  • 21
1

mysql-server is running? #service mysql statusor #mysql on command line. You can also use #mysql -u USERNAME -p or #mysql -u USERNAME -h localhost -p to check the login. See mysql man

  • Sorry for my ignorance, where is command line on Synology DSM? I tried looking for a terminal app, but couldn't find one. – Freakishly Aug 16 '17 at 16:38
  • If you use windows you can take **putty**, a free tool. On Linux do a **ssh** connection to your synology device. You can login with any account which is in the group **administrators**. To get root access you have to do **sudo -i** –  Aug 17 '17 at 08:48
1

you need to add a port.

I use PDO but you can use mysql_connect

  try
  {
     $pdo = new PDO("mysql:host=servernameport=3307;dbname=database", "username", "password");
  }
  catch(PDOException $e)
  {
     echo $e->getMessage();
  }
      return $pdo;

To find out which port you need, go to maria db if im right this package is installed automatically when you install phpmyadmin

1

I had the same problem than you. I solved it with following Host parameters:

Host: 127.0.0.1:3307

I was installing a Wordpress site importing it from Duplicator Pro PlugIn, and it worked for me.

Miq
  • 11
  • 4