PHP编程技巧

1、如果数据不存在的情况下如何插入数据

$con=mysql_connect("localhost","***","***");
mysql_select_db("temp",$con);

function recordFee($con){
while(true){
$sql = "INSERT INTO temp3(name,test) values('hello','world')";
mysql_query($sql,$con);
if(mysql_errno($con) == 1146){//如果不存在这个数据表将会报出1146的错误码
$sql = "create table temp3(
name varchar(20) not null,
test varchar(20) not null
)";
mysql_query($sql,$con);
}else{
break;
}
}

}
recordFee($con);



原文地址:https://www.cnblogs.com/bugY/p/2310210.html