·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 "<CENTER>"; PRINT "Hello, $name."; PRINT "<BR><BR>"; PRINT "Thank you for your interest.<BR><BR>"; PRINT "We will send information to $email, and have noted that you like $preference"; PRINT "</CENTER><BR><BR>";
/* 發送有關郵件*/ 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.");