資料庫鏈接失敗。錯誤資訊:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)。
用戶名,密碼,地址,都是對的。下面是我的代碼,求大神指教。
<?php
header("Content-type: text/html; charset=utf-8");
//鏈接到mysql資料庫,設定服務器地址,用戶名,地址。
//常量引數。
$dbname = 'ZUEUmNusqMJVLEhyYCCP';
/*從環境變數里取出資料庫連接需要的引數*/
$host = getenv('sqld-gz.bcehost.com');
$port = getenv('3306');
$user = getenv('99e349495cff4a95989bb74f511a8915');
$pwd = getenv('547e172845af488ba82d76c3dfafcb49');
$conn=@mysql_connect($host,$port,$user,$pwd )or die('資料庫鏈接失敗。錯誤資訊:'.mysql_error());
//第二步,選定要鏈接的資料庫,設定字符集。
mysql_select_db($dbname,$conn)or die('資料庫錯誤!!錯誤資訊:'.mysql_error());
mysql_query('SET NAMES UTF8')or die('字符設定錯誤!!錯誤資訊:'.mysql_error());
//第三部,從資料庫中選擇一張表,然后把這張表從資料庫中提取出來。
$query= 'SELECT*FROM art';
$result= mysql_query($query)or die('SQL錯誤!!錯誤資訊:'.mysql_error());
//$result就是記錄集
//第四步,將記錄集里的資料顯示出來。
print_r(mysql_fetch_array($result,MYSQL_ASSOC));
uj5u.com熱心網友回復:
在客戶端能連接么?uj5u.com熱心網友回復:
mysql服務開啟啦 ,他這個是個用phpMyadmin操作管理的uj5u.com熱心網友回復:
phpMyadmin可以鏈接操作資料庫嗎?uj5u.com熱心網友回復:
可以操作阿阿uj5u.com熱心網友回復:
百度云服務器,資料庫在服務器上面。 連接上了,謝謝。一直沒有回復。轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/116713.html
標籤:MySQL
上一篇:mysql配置innodb_flush_method 引數問題
下一篇:求問:報表怎么只打第一頁
