PHP学习笔记(三)php连接MySql数据库

php连接MySQL

	error_reporting(E_ALL & ~E_DEPRECATED);
	header('Content-type:text/html;charset=utf8');
	$conn = mysql_connect('localhost','root','root')
	or die("");
	mysql_set_charset('utf8');//5.5以下适用
	

php连接数据库

	$select = mysql_select_db('student')
	or die("");

增删改查

	$sql = "select * from student";
	$insert_sql = "insert into student values ('default','张三','23')";
	$update_sql = "update student set name = '李四' where id = 7";
	$delete_sql = "delete from student where id = 7";
	$query = mysql_query($insert_sql)//此时$query是一个数组
	or die("");

你可能感兴趣的:(php)