How to connect to connect to MariaDB5 locally on synology with PHP and MYSQL?

1.4k views Asked by At

I am trying to connect to the database I created on MariaDB5, house in my synology. But My code is not working? I have an error: "Impossible de se connecter : Host 'nasjjs.home' is not allowed to connect to this MariaDB server".

Below please find the code, thanks for your help...

<?php
$link = mysql_connect("192.168.1.31:3306", "root@localhost", "pwd","celebs")
    or die("Impossible de se connecter : " . mysql_error());
echo 'Connexion réussie';
mysql_close($link);
?>
1

There are 1 answers

0
Prince Adeyemi On

Corrected your connection code:

$link = mysql_connect("192.168.1.31", "username", "pwd","celebs")
    or die("Impossible de se connecter : " . mysql_error());
echo 'Connexion réussie';
mysql_close($link);

mysql_connect is deprecated! use PDO or MySQLi

try {
    $db = new PDO('mysql:host=192.168.1.31; dbname=celebs', 'root', 'pwd');
} 
catch (PDOException $e) {
    exit('Database error!');
}

function _cleanUp($var) {
    global $db;

        if (function_exists('mysql_real_escape_string')) {
            $cleaned = strip_tags(mysql_real_escape_string(trim($var)));
        } 
        else {
            $cleaned = strip_tags(mysql_escape_string(trim($var)));
        }
    return $cleaned;
}