Iにmysql_connect()と私のデータベースを接続し、次のPHPコードを持っているが、私は次の警告得続ける:アップデートにmysql_connect()を償却
推奨されていません:にmysql_connect():MySQLの拡張機能が廃止されましたをし、中に削除されます将来:mysqliまたはPDOを代わりに使用してください.....
私はこの接続を更新して今後何の問題もないでしょうか?
Iにmysql_connect()と私のデータベースを接続し、次のPHPコードを持っているが、私は次の警告得続ける:アップデートにmysql_connect()を償却
推奨されていません:にmysql_connect():MySQLの拡張機能が廃止されましたをし、中に削除されます将来:mysqliまたはPDOを代わりに使用してください.....
私はこの接続を更新して今後何の問題もないでしょうか?
try {
$dbh = new PDO("mysql:dbname=$db_name;host=$db_host", $db_username, $db_pass);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
<?php
//CREATED BY ...
/*
1: "die()" will exit the script and show an error statement if something goes wrong
2: A "mysql_connect()" error usually means your username/password are wrong
3. A "mysql_select_db()" error usually means the database does not exist
*/
//Place db host name. Sometimes "localhost" but
//sometimes looks like this: >> ???mysql??.someserver.net
$db_host = "localhost";
//Place the username for the MySQL database here
$db_username = "...";
//Place the password here:
$db_pass = "...";
//Place the name for the MyS
$db_name = "...";
//Run the connection right here!
mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect");
mysql_select_db("$db_name") or die("no databases");
?>
参照 'mysqli'または' PDO'を使用してスクリプトのコードを変換します。 – Barmar
*すべての* mysql_ *関数は非推奨です。コード内の* all *を置き換える必要があります。 –
https://www.sitepoint.com/migrate-from-the-mysql-extension-to-pdo/ –