0

i got a webserver running on my raspberry pi with mariadb installed. i can connect and use the database with my python scripts no problem. but when i try to connect with php:

<?php
     $dbhost = 'localhost';
     $dbuser = 'root';
     $dbpass = 'password';
     $conn = mysql_connect($dbhost, $dbuser, $dbpass);

     if(! $conn ) {
        die('Could not connect: ' . mysql_error());
     }

     echo 'Connected successfully';
     mysql_close($conn);
  ?>

the page is just blank. i even set the permissions of this .php file to 777. can anybody help me pelase?

Kai H.
  • 39
  • 1
  • 5

1 Answers1

0

mysql extension is deprecated and removed since php 7.0

Use mysqli extension or PDO instead:

http://php.net/manual/en/function.mysqli-connect.php

http://php.net/manual/en/pdo.connections.php

WayFarer
  • 1,040
  • 11
  • 19
  • first one not working either i try the second link – Kai H. Feb 14 '18 at 02:07
  • you should install mysqli extension then, on Ubuntu you can use apt-get install php7.0-mysql Find more details here: https://stackoverflow.com/questions/35424982/how-to-enable-mysqli-extension-in-php-7 – WayFarer Feb 14 '18 at 02:12
  • the PDO one drops out this: Error!: could not find driver – Kai H. Feb 14 '18 at 02:12
  • 1
    sudo apt-get install php-mysql after this and restarting its working! thanks alot guys! – Kai H. Feb 14 '18 at 02:15