要添加值,请使用
mysql_query
INSERT INTO ...
这样地:
//connect to mysql and select database
mysql_connect('localhost', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());
mysql_select_db('put_your_database_name_here') or die("Can not select database");
//insert data into MySQL
mysql_query("insert into user (id, name, room, subject, fb) values ('1', 'bob', 'B4', 'maths', 'www.facebook.com/bob')");
然后要搜索值,请执行以下操作:
//connect to mysql and select database
mysql_connect('localhost', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());
mysql_select_db('put_your_database_name_here') or die("Can not select database");
//fetch data from MySQL
$result = mysql_query("select * from user where room = 'B4'");
//iterate over each row and do what you want.
while($row = mysql_fetch_assoc($result))
{
$name = $row['name'];
$room = $row['room'];
$subject = $row['subject'];
$fb = $row['fb'];
echo $name;
}