PHP Fatal Error on mysqli_connect();

2019-08-16 22:41发布

I have looked all over the internet to try to resolve this issue but I could not find the solution to my problem, so I apologize for probably writing a duplicate question.

I am trying to link my local site to mysql on my machine. Every time that I run this code:

<?php
        ini_set('display_errors',1);
        ob_start();

        $host = "localhost";
        $user = "root";
        $pass = "[PASSWORD]";
        $db = "[DB]";

        $connection = mysqli_connect($host, $user, $pass, $db) or die("Cannot connect to database.");

        $username = $_POST['username'];
        $password = $_POST['password'];

        $result = mysqli_query($connection, "SELECT * FROM user WHERE username = '" . $username . "' AND password = '" . $password . "';");

        if ($row = mysqli_fetch_array($result)) {
                session_start();
                $_SESSION['id'] = $row['id'];
                $_SESSION['username'] = $username;
                $_SESSION['email'] = $row['email'];
                $_SESSION['profilePic'] = $row['profilePic'];
                header("Location: home.php");
        }
        else {
                print "Wrong Login. <a href='landing.php'>Go Back</a>.";
        }

        ob_flush();
?>

I always get this message:

Fatal error: Call to undefined function mysqli_connect() in /var/www/html/tts/checklogin.php on line 10

As you can assume, checklogin.php is the file shown on this question.

I am running Ubuntu 14.04 LTS on my computer, and it is very new so I probably just don't have something installed. This code works fine on my server, so it has to be something with my computer, not the code.

4条回答
迷人小祖宗
2楼-- · 2019-08-16 23:15

mysqli php extension is not installed in your new server. you need to install or Enable Or Else Contact to your server administrator.

查看更多
够拽才男人
3楼-- · 2019-08-16 23:19

Just run this in your bash:

sudo aptitude install php5-mysql
sudo service apache2 restart
查看更多
戒情不戒烟
4楼-- · 2019-08-16 23:20

mysqli php extension is not installed on your server You need to enable mysqli php extension

sudo apt-get install php5-mysql

then add

extension=mysqli.so

in your php.ini, restart apache and it should work.

ubuntu https://askubuntu.com/questions/157684/mysqli-for-php-in-package-mysql

also follow :- Extension mysqli is missing, phpmyadmin doesn't work

查看更多
小情绪 Triste *
5楼-- · 2019-08-16 23:23

Yeah it looks like you php extension is missing, get in touch with your server admin mate.

查看更多
登录 后发表回答