0

I have some issues with my PDO connexion. I try to connect my android phone to my database which is on a Raspberry PI 3.

I have in the PI folder /var/www/html/ some php files.

One of them manages the connexion to the database.

I've tried to connect via phpmyadmin with user and password and it works fine on Pi and on other computers in network.

<?php
    function connexionPDO()
    {
        $login = "XXXXXX";
        $mdp = "YYYYYYYYYYY";
        $bd = "ZZZZZZ";
        $serveur = "192.168.0.12";
        $port = "3307";
        try
        {
            echo "tentative de connexion BWAAAAAAA";
            $conn = new PDO("mysql:host=$serveur;dbname=$bd", $login, $mdp);
            echo "BWA connexion reussie";
            return $conn;
        }
        catch(PDOException $e)
        {
            echo "BWA errrrreuuuuuur";
            print "Erreur !%".$e->getMessage();
            die();
        }   
    }
?>

In the logcat in Android studio i get :

BWA errrrreuuuuuurErreur !%SQLSTATE[HY000] [2002] Connection refused

Can someone explain to me where is the problem ? ty Evo

Kevin Martins
  • 590
  • 7
  • 20
Evosub
  • 47
  • 8
  • Did you forget to use `$port`? – user3783243 Jun 15 '19 at 17:38
  • Welcome to SO. Refer to this link [link](https://stackoverflow.com/questions/29395452/php-connection-failed-sqlstatehy000-2002-connection-refused) and see if it helps. Main issue seems to be with your Port. – Mohammed Akhtar Zuberi Jun 15 '19 at 17:46
  • It works Mohammed ! Ty !! I change 192.168.0.12 with localhost and it is good now – Evosub Jun 15 '19 at 17:57
  • 2
    Possible duplicate of [PHP Connection failed: SQLSTATE\[HY000\] \[2002\] Connection refused](https://stackoverflow.com/questions/29395452/php-connection-failed-sqlstatehy000-2002-connection-refused) – Imperishable Night Jun 15 '19 at 19:18

0 Answers0