一個(gè)簡單的自動(dòng)發(fā)送郵件系統(tǒng)(二)_PHP教程
Jul 21, 2016 pm 04:06 PM
這里介紹php和mysql結(jié)合起來實(shí)用。
????基本上,可以說php是介于后臺(tái)數(shù)據(jù)庫和前臺(tái)瀏覽器的一個(gè)中間層,在他們之間傳遞命令。這種方式大大提高了交互的可能性,可以方便使用在投票系統(tǒng),其他動(dòng)態(tài)用戶輸入和個(gè)性化網(wǎng)站中。
????要想實(shí)現(xiàn)這種交互,首先必需實(shí)現(xiàn)和mysql數(shù)據(jù)庫連接,可以使用這個(gè)命令實(shí)現(xiàn):
????語法:int mysql_connect(string hostname, string username, string password);??
????·hostname - 運(yùn)行數(shù)據(jù)庫服務(wù)器所在的主機(jī)名稱。
????·username - 連接到數(shù)據(jù)庫服務(wù)器的用戶名稱。
????·Password - 用戶密碼。the password set to connect to the MySQL database.??
?????如果連接成功,函數(shù)返回一個(gè)正整數(shù),如果失敗返回一個(gè)負(fù)數(shù)。
?????所有的命令,和往常一樣,必需放置在"" 和 "?>"之間。
?????讓我們繼續(xù)我們的工程,讓我們假設(shè)用MySQL建立了以下的數(shù)據(jù)表:
----------------------------????
mysql> CREATE TABLE information (
????-> name VARCHAR (25),
????-> email VARCHAR (25),????
????-> choice VARCHAR (8) );
----------------------------????
????現(xiàn)在讓我們假設(shè)我們要吧用戶的信息插入到這個(gè)數(shù)據(jù)庫中,我們可以通過修改email.php3腳本來實(shí)現(xiàn),修改如下:
----------------------------????
/* 這個(gè)腳本將使用從moreinfo.html文件中傳遞過來的變量。 */
/* 聲明一些相關(guān)的變量 */
$hostname = "devshed";
$username = "myusername";
$password = "mypassword";
$dbName = "mydbname";
/* 使用MySQL建立的數(shù)據(jù)表存取信息??*/
$userstable = "information";
/* 網(wǎng)站管理員的郵件地址*/
$adminaddress = "administration@buycorn.com";
/* 與數(shù)據(jù)庫連接*/
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 "
";
/* 發(fā)送有關(guān)郵件*/
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.");
/* 將數(shù)據(jù)插入數(shù)據(jù)表中*/
$query = "INSERT INTO $userstable VALUES('$name','$email', '$preference')";
$result = MYSQL_QUERY($query);
PRINT "Your information has also been inserted into our database, for future reference.";
/* 關(guān)閉與數(shù)據(jù)庫的連接*/
MYSQL_CLOSE();
?>
----------------------------????
一些注意的地方:
1、在腳本一開始聲明的變量是為了函數(shù)MYSQL_CONNECT() 。我們也可以直接在函數(shù)中將這些值給出,可是,考慮工程的可發(fā)展性,這些值應(yīng)該放在一個(gè)獨(dú)立的文件中,用(#include)調(diào)入。
2、語法: int mysql_select_db(string database_name, int link_identifier);
·database_name??必需是在服務(wù)器上的數(shù)據(jù)庫名。
·link_identifier(可選的) 是指明連接,基于此向數(shù)據(jù)庫服務(wù)器發(fā)出請求。
·返回值為true/false
3、語法: int mysql_query(string query, int link_identifier);
·query??發(fā)送向mysql服務(wù)器的sql命令。
·link_identifier(可選擇)??指明連接,基于此向數(shù)據(jù)庫服務(wù)器發(fā)送sql命令。
·返回值為整數(shù),正數(shù)表示成功了,負(fù)數(shù)表示失敗。
4、語法: int mysql_close(int link_identifier);??
·link_indentifier??與上面相同
·返回值為整數(shù),正數(shù)表示成功了,負(fù)數(shù)表示失敗。
在下一篇文章中,我將給大家講解如何從mysql中輸出數(shù)據(jù)。?

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











STD :: Chrono? ?? ?? ??, ?? ?? ??, ?? ?? ? ?? ?? ? ?? ?? ??? ???? C?? ???? ??? ?????. 1. std :: chrono :: system_clock :: now ()? ???? ?? ??? ?? ? ??? ?? ??? ???? ?? ? ? ??? ??? ??? ???? ?? ?? ? ????. 2. std :: Chrono :: steady_clock? ???? ?? ??? ???? ?? ??? ???? duration_cast? ?? ?? ?, ? ? ?? ??? ??????. 3. ?? (time_point) ? ?? (??)? ?? ??? ? ? ??? ?? ??? ? ?? epoch (epoch)???? ???????.

toaccessenvironmentvariablesinphp, usegetenv () ?? $ _envsuperglobal.1.getenv ( 'var_name') retrievespescificvariable.2. $ _ en v [ 'var_name'] accessesvariablesifvariables_orderinphp.iniincludes "e".setvariablesviacliwithvar = valuephpscript.php, inapach

CTE? ??? ??? ????? ? ???? MySQL? ?? ?????. ?? ???? ?? ? ???? ?? ??? ? ?? ??? ???? ? ????. ?? ??, ?? ???? ? ???? ?? ?? ??? ?? ? ?? CTE? ?? ? ???? ?? ?? ??? ?? ?? ?? ???? ???? ?? ???? ?? ? ????. ?? ??? ???? CTE ??? ???? ??? ?????? ? ????. ?? ??? ?? ? ??, ?? CTE? ???? ?? CTE? ?? ???? ???? ?? ?????. CTE ??? ?? SQL??? ???? ????? ?? ? ????.

phphasthreecommentstyles : //, #forsingle-lineand/.../formulti-lline.usecommentstoexplainwhycodeexists, notwhatitdoes.marktodo/fixMeitemsandDisableCodeTemporlinlyDuingDeBugging.aVoidOver-commentingsimplOgic.writeCoCoCoCoCoConcomeCOCOCOCONCOCOCOCOCOCOCOCOCISE

"undefinedIndex"??? ??? ? ?? ?? ??? ????. ??, ISSET ()? ???? ?? ?? ????? ???? ?? NULL? ??? ??????. ?? ?? ???? ????? ?????. ??, array_key_exists ()? ???? ?? ????? ?? ? ?????. ?? ?? ???? ?? ?? NULL ? ??? ?????. ????? ? ?? ???? ??????. (PHP7) ?? PHP ????? ???? ???? ???? ???? ?? ?? ??? ??????? ???? Extract ()??? ?? ????, ??? ?? ?? ??? ???? ????? ?? ??? ? ?????.

PHP ??? ???? ???? ???? ??? ??? ? 1. ??? ??? ?? ?? ???? ???? ?????. 2. PDO? ??? ?? ??? ?? ???? Array_Values? ???? ?? ???? ?? ? ? ????. 3. MySQLI? ??? ?? ?? ???? ???? ?? ??? ??????? ?? ? ?? ???? ???? ?????? ???????. 4. SQL ? ??? ?, ? ?? ?? ? ??? ??? ????? ??????. ???? ??? ??? ????. ?? Alflode ? Array_fill? ???? ?? ???? ?? ? ?? ?? ? ??? ?? ?? ??? ????? ??? ???? ?????.

USSETTINGUTUPMYSQLTABLES? ??? ? DATATYPESSISCECIALFORFOILICION ? SCALIBICTION? ??????

?? ?? ?? ??? ?? ??? ??? : 1. ?? ?? ??? ??? ?? ?? ??? ???? ????? OB_START () ??? ???????. 2. ??? ???? ??? ?? ?? ??? ???? ?? ?? ?? ?? ?? ???????. 3. ?? ??? ?? ?? ? ?? ? ??? ?? ???? ???? ???? ?? ???????. 4. ?? ?? ?? ?? ??? ??? ??? ??? ???? ?? ???? ?? ? ? ????.
