·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.");