·hostname - 運行資料庫伺服器所在的主機名稱。
·username - 串連到資料庫伺服器的使用者名稱稱。
·Password - 使用者密碼。the password set to connect to the MySQL database.
如果串連成功,函數返回一個正整數,如果失敗返回一個負數。
所有的命令,和往常一樣,必需放置在""之間。
讓我們繼續我們的工程,讓我們假設用MySQL建立了以下的資料表:
----------------------------
mysql> CREATE TABLE information (
-> name VARCHAR (25),
-> email VARCHAR (25),
-> choice VARCHAR (8) );
/* 與資料庫連接*/
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
PRINT "";
PRINT "Hello, $name.";
PRINT "
";
PRINT "Thank you for your interest.
";
PRINT "We will send information to $email, and have noted that you like $preference";
PRINT "
";
/* 發送有關郵件*/
mail("$email", "Your request for information",
"$namenThank you for your interest!n
We sell fresh corn daily over the Internet!
Place your order at http://www.buycorn.com,
and receive a free package of $preference!");
mail("$adminaddress",
"Visitor request for info.",
"$name requested for information.n
The email address is $email. n The visitor prefers $preference.");