2014-02-06 105 views
0

我連接亞馬遜RDS使用PHP使Web服務亞馬遜我的SQL RDS,但它不連接到這裏的服務器是我的代碼無法連接使用PHP

<?php 

try{ 
$dbhost = 'myrds.cjahuqpumuov.us-east-1.rds.amazonaws.com:3306'; 
$username = 'myname'; 
$password = 'mypassword'; 
$dbname = 'mydb'; 

$link = mysql_connect($dbhost, $username, $password, $dbname); 
mysql_select_db($dbname); 

} 

catch(Exception e){ 

echo e 

} 
?> 

解析錯誤:語法錯誤,意外T_STRING,預計在T_VARIABLE上/home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/selectTest.php線路17

錯誤跟蹤

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 110 in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/selectTest.php on line 12 

Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/selectTest.php on line 13 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/selectTest.php on line 13 

回答

0

我覺得主機名w^ith端口號是不允許你連接..嘗試通過刪除端口號如:

$dbhost = 'myrds.cjahuqpumuov.us-east-1.rds.amazonaws.com'; 

我也面臨同樣的問題前幾天。

+0

顯示同樣的問題解析錯誤有用解決/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/selectTest.php第17行 – user3278422

+0

你以前用'http://'試過了。 'http:// myrds.cjahuqpumuov.us-east-1.rds.amazonaws.com' –

+0

並且我可能知道主機名是正確的嗎? –

0
<?php 

try{ 
$dbhost = 'myrds.cjahuqpumuov.us-east-1.rds.amazonaws.com'; 
$username = 'myname'; 
$password = 'mypassword'; 
$dbname = 'mydb'; 

$link = mysql_connect($dbhost, $username, $password, $dbname, 3306); 
mysql_select_db($dbname);  
} 
catch(Exception $e){  
echo 'Caught exception: ', $e->getMessage(), "\n";  
} 
?> 
+0

提供相同的錯誤,如上所述 – user3278422

+0

請在語句中將e更新爲$ e。 – jainvikram444

+0

加了echo 0f $ E問題upadted請檢查 – user3278422

0
dbhost = "hostname:port"; //default is 3306  
$link = mysql_connect($dbhost, $username, $password); 

您需要通過端口號與主機名。

+0

我不使用ec2其rds amaozon – user3278422

+0

是的,對不起,我也在談論亞馬遜rds。看到這是我如何使用rds amazon db: 'define('_ E_DB_PRIMARY','enterprise-db-dev.xyz.com:3306'); define('_ E_DB_USER','enterprise_dev'); define('_ E_DB_PASSWORD',''); 定義( '_ E_DB_DATABASE', 'enterprise_dev')' –

+0

你能在我的問題編輯目前尚不清楚,請 – user3278422