注明:(使用XAMPP下)
1、新建数据库:
地址栏中输入: http://localhost/phpmyadmin/
按照页面上的提示新建好数据库即可。
tips:在建表时可以选择id自动增长。
2、连接数据库:
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
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、查询数据库:
<?php
$searchCatagory = "select * from catagory;";
$result = mysql_query($searchCatagory);
?>
4、插入新数据:
$sql_insert_qustion = "insert into questions (title,content,tags,time)
values('".$_POST['title']."','".$_POST['content']."','".$_POST['tags']."',now());";
mysql_query($sql_insert_qustion);
获得新插入条目的ID号:
$questionID = mysql_insert_id();