エラー : Warning: mysql_error(): 9 is not a valid MySQL-Link

WordPressで、こんなエラーが出た人ー。(はーい)

Warning: mysql_error(): 9 is not a valid MySQL-Link resource in /home/dacelo/wordpress/wp-includes/wp-db.php on line 615

WordPress上で、何か別のPHPプログラムを実行したりしていませんか。
これは、MySQLデータベースへのコネクトが被っているために出ているエラーです。

じゃあこういう場合はどうすればいいのかというと、MySQL4.2以降のmysql_connectには、[new_link]というパラメータがあり、これで複数の接続が出来るようになっています!

広告

マニュアルを見てみましょう。

new_link

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.

PHP: mysql_connect – Manual

具体的に例を挙げると、
これを…

 $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
 if(!$conn){
     die("db connect Error");
 }

こうします。

 $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true);
 if(!$conn){
     die("db connect Error");
 }

これで表題のエラーは表示されなくなるはずです。

About: dacelo


1 thought on “エラー : Warning: mysql_error(): 9 is not a valid MySQL-Link”

Leave a Reply

Your email address will not be published. Required fields are marked *