$host = '遠程伺服器ip';$root = '使用者名稱';$pwd = '密碼';$con = @mysql_connect($host,$root,$pwd);mysql_query("set names 'utf8'");@mysql_select_db("XS_CQC", $con) or die(mysql_error());
我串連本地的資料庫是正常,但是串連遠端話報這個錯誤。
Access denied for user 'ODBC'@'localhost' (using password: NO)
這個是什麼意思?
回複討論(解決方案)
現在是 代碼在一個伺服器, 資料庫在另外一個伺服器。
是不是My Code有問題?
遠端連線 MySQL,需要對方授權
連結遠端資料庫的帳號要有遠程連結的許可權
在資料庫中執行
> GRANT ALL PRIVILEGES ON 資料庫名稱.* TO '使用者名稱'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;
> FLUSH PRIVILEGES;
這樣就可以了
$host = 'localhost'; $root = 'ODBC'; $pwd = ''; $con = @mysql_connect($host,$root,$pwd); mysql_query("set names 'utf8'"); @mysql_select_db("XS_CQC", $con) or die(mysql_error());
敢問你的原始碼是這麼寫的麼.. 不是連遠程伺服器麼. 你的ip和使用者密碼貌似都沒改.
沒有連結許可權,
在對方的mysql 資料庫中需要什麼存取權限。
在phpmyadmin中設定user,host
$host = 'localhost'; $root = 'ODBC'; $pwd = ''; $con = @mysql_connect($host,$root,$pwd); mysql_query("set names 'utf8'"); @mysql_select_db("XS_CQC", $con) or die(mysql_error());
敢問你的原始碼是這麼寫的麼.. 不是連遠程伺服器麼. 你的ip和使用者密碼貌似都沒改.
源碼就是上面寫的遠程伺服器的IP,只是不方便透漏伺服器的IP跟 使用者名稱。 就打上中文了