Note: (use XAMPP)
1. Create a database:
Enter http: // localhost/PHPmyAdmin/in the address bar/
Follow the prompts on the page to create a database.
TIPS: You can select ID to automatically increase when creating a table.
2. Connect to the database:
Code
1 <? PHP
2 $ Dbhost = " Localhost " ;
3 $ Dbuser = " Root " ;
4 $ Dbpassword = " 1234 " ;
5
6 $ Dbdatabase = " Testaq " ;
7 $ DB = Mysql_connect ( $ Dbhost , $ Dbuser , $ Dbpassword );
8 Mysql_query ( " Set names 'utf8' " );
9 Mysql_select_db ( $ Dbdatabase , $ DB );
10 ?>
3. query the database:
<?PHP
$ Searchcatagory = "Select * From catagory;";
$ Result = Mysql_query($ Searchcatagory);
?>
4. Insert new data:
$ SQL _insert_qustion = " Insert into questions (title, content, tags, time)
Values (' " . $ _ Post [ ' Title ' ] . " ',' " . $ _ Post [ ' Content ' ] . " ',' " . $ _ Post [ ' Tags ' ] . " ', Now ()); " ;
Mysql_query ( $ SQL _insert_qustion );
Obtain the ID number of the newly inserted entry:
$ Questionid = Mysql_insert_id();