Connecting to MariaDB

Chaandgus
Posts: 4
Joined: Mon Aug 30, 2021 4:00 am

Re: Connecting to MariaDB

Post by Chaandgus »

Hello Steven, forgive me for re-digging the subject but I need skills that are yours...if you accept the challenge.

I had to reinstall PHPMyAdmin and MariaDB.

I have created my database and my user. I can connect to it using SSH

Code: Select all

mysql -u user -p database
However, I get a blank page when I use the following method:

Code: Select all

<!DOCTYPE html>
   <head>
      <title>Connect to MariaDB Server</title>
   </head>

   <body>
      <?php
         $host = 'host:3307'; //host name
         $name= 'database'; //Name of the data base
         $user = 'user'; //user
         $pass = 'password';

         $conn = mysqli_connect($host, $user, $pass);
      
         if(! $conn ) {
            die('Could not connect: ' . mysqli_error());
    
         }
         
         echo 'Connected successfully';
         mysqli_close($conn);
      ?>
   </body>
</html>
Could you give me an advise please ?

My sockets are /run/mysqld/mysqld.sock in MariaDB and /run/mysqld/mysqld.sock in PHPMyAdmin.

excepted that, I really doesn't know what should be the trouble.
steven
Posts: 132
Joined: Sun Oct 01, 2017 3:08 pm

Re: Connecting to MariaDB

Post by steven »

If you you are using the code exactly as shown in your post, you are closing the database connection before you do anything. The connection must remain open when getting or writing data. If PHP closes the connection before reading database data to variables or arrays, nothing happens.