简体   繁体   中英

Why is this PHP script not connecting to the MySQL database correctly?

I've created for following simple script to connect to an associated MySQL database:

<?php
$con = mysqli_connect("localhost","username","password", "database");

if (!$con)
{
  die('Could not connect: ' . mysqli_connect_error());
}

echo "test";

mysqli_close($con);
?>

Initially, this gave the error message

Fatal Error: Call to undefined function mysqli_connect()

Having googled this error message, I discovered that it meant that there was an issue which I needed to sort out with my host. I did this, and they made some changes to my account. Now however, instead of giving me the error message, it doesn't do anything at all (even if I change the login credentials to incorrect ones). No error message. Nothing. If I try to access the php file directly through a web browser (IE11), it gives the following message:

错误

Why is this happening?

var_dump(function_exists('mysqli_connect'));

如果输出为FALSE,则它不存在,并且您没有mysqli模块。

<?php
  try
   {
     $bdd = new PDO('mysql:host=localhost;dbname=your_db_name', 'username', 'password');
   }
  catch(Exception $e)
  {
     die('Error : '.$e->getMessage());
    }
?>

Try this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM