PHP对mysql数据库的插入记录

来源:互联网 发布:大数据的特点 编辑:程序博客网 时间:2024/05/22 05:19

向MySQL数据库中添加记录;

以demo数据库,student表为例(有id,stuname,stuAge,tel几个字段)


连接数据库(数据库没有密码)

$mysql=new mysqli("localhost","root","","demo");    

  if($mysqli->connect_error()){

      die("连接数据库失败。。").mysqli->connect_error();

}

echo "连接数据库成功!";  


错误写法:

正确的写法

$sql="INSERT INTO student(id,stuname,stuAge,tel)VALUE(1001,'zhangshan',20,'132xxxxxxxx')";



原创粉丝点击