2016-12-29 6 views
-1

Iにmysql_connect()と私のデータベースを接続し、次のPHPコードを持っているが、私は次の警告得続ける:アップデートにmysql_connect()を償却

推奨されていません:にmysql_connect():MySQLの拡張機能が廃止されましたをし、中に削除されます将来:mysqliまたはPDOを代わりに使用してください.....

私はこの接続を更新して今後何の問題もないでしょうか?

+1

参照 'mysqli'または' PDO'を使用してスクリプトのコードを変換します。 – Barmar

+2

*すべての* mysql_ *関数は非推奨です。コード内の* all *を置き換える必要があります。 –

+0

https://www.sitepoint.com/migrate-from-the-mysql-extension-to-pdo/ –

答えて

0
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"); 
 
?>
詳細はこちら http://php.net/manual/de/pdo.prepare.php

+0

彼は接続と選択機能を求めましたが、これ以上は要注意です!もっと彼はPHPのドキュメントを読むことができます! – Eugen

+0

罰金、サイトポイントへのあなたのリンクははるかに役立ちます...もっと多くのPHPのドキュメントより: - / – Eugen

関連する問題