Php --- mysql simple application --- online dictionary // Constructor, initialize data, connect to database $ this-& gt; conn = mysql_connect ($ this-& gt; host, $ this-& gt; user, $ this-& gt; password );
[Html]
Insert title here
Enter the English word you want to search:
Insert title here
Enter the English word you want to search:
[Php] view plaincopyprint?
Class DicTool {
Private $ conn;
Private $ host = "localhost ";
Private $ user = "root ";
Private $ password = "123 ";
Private $ db = "test ";
// Constructor, initialize data, connect to database
Function _ construct (){
$ This-> conn = mysql_connect ($ this-> host, $ this-> user, $ this-> password );
If (! $ This-> conn ){
Die ("failed to connect to database". mysql_error ());
}
// Select a database
Mysql_select_db ($ this-> db, $ this-> conn );
Mysql_query ("set names utf8 ");
}
Function findchword ($ enword ){
$ SQL = "select * from words where enword = '". $ enword. "'limit ";
$ Res = mysql_query ($ SQL, $ this-> conn) or die (mysql_error ());
If (! $ Res ){
Return 0; // failed
} Else {
$ Row = mysql_fetch_assoc ($ res );
Return $ row ['chword'];
}
}
}
Header ("Content-Type: text/html; charset = UTF-8 ");
Include_once 'dictool. class. php ';
$ DicTool = new DicTool ();
If (isset ($ _ POST ['enword']) {
$ Chword = $ dicTool-> findchword ($ _ POST ['enword']);
If ($ chword ){
Echo $ _ POST ['enword']. "the corresponding Chinese meaning is:". $ chword ."
";
} Else {
Echo "No results found!
";
}
} Else {
Echo "no input is obtained!
";
}
Echo "click to return
";
Header ("Content-Type: text/html; charset = UTF-8 ");
Include_once 'dictool. class. php ';
$ DicTool = new DicTool ();
If (isset ($ _ POST ['enword']) {
$ Chword = $ dicTool-> findchword ($ _ POST ['enword']);
If ($ chword ){
Echo $ _ POST ['enword']. "the corresponding Chinese meaning is:". $ chword ."
";
} Else {
Echo "No results found!
";
}
} Else {
Echo "no input is obtained!
";
}
Echo "click to return
";