简体   繁体   中英

Error 500 when I try to connect MySql with php's mysqli

I have written below php code to connect MySQL DB:

    <?php
// Connect to MySQL
$servername = "localhost";
$username = "user";
$password = "A11b22c33&";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

However this code fails to make any connection. All I am getting is below error:

currently unable to handle this request.
HTTP ERROR 500

However if I remove the connection portion of my code then my php file working perfectly, ie I am getting echo as 'Connected successfully'

<?php
// Connect to MySQL
$servername = "localhost";
$username = "user";
$password = "A11b22c33&";


echo "Connected successfully";
?>

Can somebody help me to understand what went wrong? I have checked username and password, and they are perfect

我刚安装mysqlnd使用apt-get install php-mysqlnd ,并能正常工作。

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