大家好,初學php和mySQL沒想到馬上就卡關了...
以下是參考書籍中的其中一個範例,

<?php
$dbc = mysqli_connect('127.0.0.1:0', 'root', '' , 'aliendatabase')
or die('Error connecting to MySQL server.');

$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
"how_many, alien_description, what_they_did, fang_spotted, other, email) " .
"VALUES('Sally', 'Jones', '3 days ago', '1 day', 'four', 'green with six tentacles', " .
"'We just talked and played with a dog', 'yes', 'I have seen your dog. Contact me.', " .
"'[email protected]')";

$result = mysqli_query($dbc, $query)
or die('Error querying database.');

mysli_close($dbc);
?>

我主要是在紅字的部分卡關,進行測試後畫面出現

Warning: mysqli_connect(): (HY000/2002): Can't assign requested address in /Users/ssuhsien/Sites/owen/index.php on line 2
Error connecting to MySQL server.

我上網搜尋過了,但一直無法找到答案,想請問有人知道怎麼解決嗎?
我確認資料庫aliendatabase確實有被建立,但不知為何一直連不上線
文章關鍵字
'127.0.0.1:0', 'root', '' , 'aliendatabase'

改成以下
'localhost', 'root', '你的mysql密碼', 'aliendatabase'
貓老闆
byssuhsien wrote:
$dbc = mysqli_connect('127.0.0.1:0', 'root', '' , 'aliendatabase')

127.0.0.1:0?
不应该是127.0.0.1:3306

风见一姬 wrote:
127.0.0.1:0...(恕刪)


這個可以改..
謝謝大家的建議

不過我把條件改成'localhost', 'root', '你的mysql密碼', 'aliendatabase'後,畫面跑出以下訊息:

Warning: mysqli_connect(): (HY000/2002): No such file or directory in /Users/ssuhsien/Sites/owen/index.php on line 2
Error connecting to MySQL server.



把127.0.0.1:0改成127.0.0.1:3306跑出的錯誤訊息:

Warning: mysqli_connect(): Server sent charset (255) unknown to the client. Please, report to the developers in /Users/ssuhsien/Sites/owen/index.php on line 2

Warning: mysqli_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers in /Users/ssuhsien/Sites/owen/index.php on line 2
Error connecting to MySQL server.


請問有人知道到底是哪個環節出錯了嗎?謝謝






單引號或雙引號不知道有沒有關係?

lewis88 wrote:
單引號或雙引號不知道...(恕刪)


這我有確認過,應該不是引號的問題...
我建議拉
樓主先從Appserv 起手
哪個比較簡單幫你把MSSQL + PHP + Apache 都弄好了
網路上教學也很多
你會比較知道問題在哪
不然這問題解決之後後面還有一堆問題等你
到真的編寫php 都不知道到何年何月..
既然是初學,建議先從架XAMPP開始...
我最近剛好在玩ARDUINO
有用到PHP跟MYSQL(WAMP)

我個人是用PDO去連mysql
https://ithelp.ithome.com.tw/articles/10187915

我也是摸了很久!才搞定 順便把程式碼打成自己看得順眼的
需要幫忙再私訊!!!
關閉廣告
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!