データベースに接続しようとしていますが、mysql_connect関数でエラーが表示されます。MySQL Connect機能が動作しません。
エラー: 致命的なエラー:未知のエラー:C:\ xampp \ htdocs \ Connect.phpで未定義の関数mysql_connect()を呼び出す:12スタックトレース:#0 C:\ xampp \ htdocs \ Test.php (3):\ 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";
?>
()#1 {メイン} Cでスロー必要
どのバージョンの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