我想连接到我的数据库,但它显示我在mysql_connect函数中的错误。MySQL连接功能不起作用?
错误代码: 致命错误:未捕获错误:调用未定义的函数mysql_connect()在C:\ xampp \ htdocs \ Connect.php中:12堆栈跟踪:#0 C:\ xampp \ htdocs \ Test.php (3):要求()#1 {主}扔在C:\ XAMPP \ htdocs中\ Connect.php第12行
的连接文件:
<?php
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "root";
// Place the password for the MySQL database here
$db_pass = "";
// Place the name for the MySQL database here
$db_name = "oscar";
// Run the connection here
$con = mysql_connect("db_host","$db_username","$db_pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name", $con);
try
{
$conn = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_pass);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
该文本文件:
<?php
// Connect to the MySQL database
require "Connect.php";
echo "Success";
?>
它是什么版本的PHP?你知道'mysql'函数已被弃用并从PHP 7+中删除? – RamRaider
什么是你的PHP版本。 mysql_connect 此扩展在PHP 5.5.0中被弃用,并且在PHP 7.0.0中被删除。 – ToujouAya
这行错误:$ con = mysql_connect(“db_host”,“$ db_username”,“$ db_pass”);' – Akintunde007