duanfei8897 2018-04-26 16:27
浏览 532
已采纳

PHP 7.2.4无法连接到我的MySQL 8.0

This is the error I get...

Failed with mysqli_connect()

and also with new mysqli If I put this line in comment "$conn = mysqli_connect..." I don't get the error since it doesn't try to connect to the DB.

Fatal error: Uncaught Error: Call to undefined function Classes\Connection\mysqli_connect() in C:\Apache24\htdocs\ControlePM\Classes\Connection\DBConnect.php:21 Stack trace: #0 C:\Apache24\htdocs\ControlePM\index.php(22): Classes\Connection\DBConnect->connect() #1 {main} thrown in C:\Apache24\htdocs\ControlePM\Classes\Connection\DBConnect.php on line 21

This is my connection code

I tried with new mysqli same error.

<?php
    namespace Classes\Connection;
    class DBConnect
    {
    var $host;
    var $username;
    var $password;
    var $database;
    public $dbc;
    public $connInfo=FALSE;

    public function __construct(){
        $this->host = 'localhost:3306';
        $this->username = 'root';
        $this->password = 'MyPassWord';
        $this->database = 'MyDB';
    }
    public function connect()
    {
        $conn = mysqli_connect($this->host,$this->username,$this->password,$this->database); 

    if (! $conn) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
        exit;
    }
    echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
    mysqli_close($conn);
    }
?>

Index.php

<?php 
require_once ('Classes/Connection/DBConnect.php'); 
$conn = new DBConnect();
$conn->connect();

if (! $conn->connInfo){
    $result = "Connection failed";
}
else $result = "Connection Succes";
?>

What am I missing?

  • 写回答

2条回答 默认 最新

  • dongying7667 2018-05-28 18:27
    关注

    My mysqli was missing from the PHP build

    In the PHP.ini file "extension=mysqli" was commented

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信