<?php $conn = mysql_connect('localhost','root','11111'); if (!$conn) { echo '连接失败!' ; exit; } $sql = ' use test'; $rs = mysql_query($sql,$conn); $sql ='set names utf8'; mysql_query($sql,$conn); $id =rand(1,100); $sname = substr(str_shuffle('asdsadasdwqrfdsfcvxcgdfg'),0,6); $sql = "insert into stu values ($id,'$sname','$sname')"; mysql_query($sql,$conn); if ($rs) { echo '新添加成功'; }else{ echo '新添加失败'; } ?>
解析:insert into 插入
mysql_query 函数
rand 函数
substr 函数
str_shuffle函数