① 怎么用php在mysql创建一表,并且要id字段为自增长的,
$servername="localhost";
$username="username";
$password="password";
$dbname="myDB";
//创建连接
$conn=newmysqli($servername,$username,$password,$dbname);
//检测连接
if($conn->connect_error){
die("Connectionfailed:".$conn->connect_error);
}
//sqltocreatetable
$sql="CREATETABLEMyGuests(
idINT(6)UNSIGNEDAUTO_INCREMENTPRIMARYKEY,
firstnameVARCHAR(30)NOTNULL,
lastnameVARCHAR(30)NOTNULL,
emailVARCHAR(50),
reg_dateTIMESTAMP
)";
if($conn->query($sql)===TRUE){
echo"";
}else{
echo"Errorcreatingtable:".$conn->error;
}
$conn->close();