mysqli_connect()上的PHP致命错误; [英] PHP Fatal Error on mysqli_connect();

查看:185
本文介绍了mysqli_connect()上的PHP致命错误;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Internet上四处寻找解决问题的方法,但是找不到解决方案,因此对可能重复的问题深表歉意.

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.

我正在尝试将本地站点链接到机器上的mysql.每次我运行这段代码:

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();
?>

我总是收到此消息:

致命错误:在以下位置调用未定义的函数mysqli_connect() /var/www/html/tts/checklogin.php,第10行

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

您可以假设,checklogin.php是此问题上显示的文件.

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

我在计算机上运行Ubuntu 14.04 LTS,它非常新,所以我可能没有安装任何东西.该代码可以在我的服务器上正常工作,因此必须与计算机配合使用,而不是代码.

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.

推荐答案

服务器上未安装mysqli php扩展名,您需要启用mysqli php扩展名

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

sudo apt-get install php5-mysql

然后添加

extension=mysqli.so

在您的php.ini中,重新启动apache,它应该可以工作.

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

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

也请遵循:-扩展名mysqli丢失,phpmyadmin不起作用

这篇关于mysqli_connect()上的PHP致命错误;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆