<? PHP
$ User = " Root " ;
$ Passwd = "Root " ;
$ Connect = Mysql_connect ( ' Localhost ' , $ User , $ Passwd )
Or Die ( ' Database Connection Failed: ' . Mysql_error ());
Echo ' <Br> <B> Step 1: </B> the connection is established successfully! <Br> ' ;
$ DB = ' Test ' ;
Mysql_select_db ( $ DB ) Or Die ( ' Cocould not select database ( ' . $ DB . ' ) Because: ' . Mysql_error ());
Echo ' <B> Step 2: </B> connect ( ' . $ DB . ' )! <Br> ' ;
Mysql_close ( $ Connect );
Echo " Nickname " ;
?>
Obtain information in the database
<? PHP
$ User = " Root " ;
$ Passwd = " Root " ;
$ Connect = Mysql_connect ( ' Localhost ' , ' Root ' , 'Root' ' )
Or Die ( ' Cocould not connect: ' . Mysql_error ());
Mysql_query ( " Set names 'gb2312' " , $ Connect );
Echo ' <B> Step 1: </B> the connection is established successfully! <Br> ' ;
$ DB = ' Test ' ;
Mysql_select_db ( $ DB ) Or Die ( ' Cocould not select database ( ' . $ DB . ' ) Because: ' . Mysql_error ());
Echo ' <B> Step 2: </B> connect ( ' . $ DB . ' )! <Br> ' ;
$ Query = ' Select * from user ' ;
$ Result = Mysql_query ( $ Query ) Or Die ( ' Query failed: ' . Mysql_error ());
Echo " <Br> <B> obtain data... </B> <br> " ;
Echo " <Table border = '1' width = '000000'> \ n " ;
$ Count = 0 ;
While ( $ Line = Mysql_fetch_array ( $ Result , Mysql_assoc )){
Echo " \ T <tr> \ n " ;
Foreach ( $ Line As $ Col_value ){
Echo " \ T <TD> $ Col_value </TD> \ n " ;
}
$ Count ++ ;
Echo " \ T </tr> \ n " ;
}
Echo " </Table> \ n " ;
If ( $ Count < 1 ){
Echo " <Br> no records found in the table. <br> " ;
} Else {
Echo " <Br> The table contains " . $ Count . " Row record. <br> " ;
}
Mysql_free_result ( $ Result );
Mysql_close ( $ Connect );
?>