我有一个在数据库中插入用户的脚本。它曾经与MYISAM一起工作,但由于我更改为INNODB,它只插入第一行,然后停止。
这是脚本。它基本上获取所有 facebook 朋友并检查用户是否在数据库中。如果不是,它将创建一个新的“未注册”用户。由于我更改为 INNODB,它只插入第一个用户。我还将发布表创建代码。有小费吗?
$data = explode(";", $_POST['data']);
for($i=0; $i<count($data); $i++){
$user = explode("^", $data[$i]);
$fname = $user[0];
$lname = $user[1];
$face_uid = $user[2];
$birthday = $user[3];
$gender = $user[4];
$temp_birth = explode("/", $birthday);
if(count($temp_birth)!=3){
$birthday="0000-00-00";
} else {
$birthday = $temp_birth[2]."-".$temp_birth[0]."-".$temp_birth[1];
}
if(ctype_alnum(str_replace(" ", "", $fname)) && ctype_alnum(str_replace(" ", "", $lname))){
$result = mysql_query("SELECT * FROM popguest.user WHERE face_uid='$face_uid'");
$row=mysql_fetch_array($result);
if(mysql_num_rows($result)==0){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen( $chars );
$verify=0;
while($verify==0){
$username='';
for($j = 0; $j < 10; $j++) {
$username .= $chars[ rand( 0, $size - 1 ) ];
}
$result2 = mysql_query("SELECT * FROM popguest.user WHERE username='$username'");
if(mysql_num_rows($result2)!=0){
$verify=0;
}else{
$verify=1;
}
}
$result = mysql_query("INSERT INTO popguest.user (face_uid, username, fname, lname, birthday, gender, registered) VALUES ('$face_uid', '$username', '$fname', '$lname', '$birthday', '$gender', '0')");
echo $fname." ".$lname.";".$face_uid.";".$birthday.";".$gender."\n";
} else {
}
} else {
}
}
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(10) COLLATE latin1_general_ci NOT NULL,
`face_uid` varchar(15) COLLATE latin1_general_ci NOT NULL,
`fname` varchar(25) COLLATE latin1_general_ci NOT NULL,
`lname` varchar(25) COLLATE latin1_general_ci NOT NULL,
`email` varchar(50) COLLATE latin1_general_ci NOT NULL,
`gender` varchar(6) COLLATE latin1_general_ci NOT NULL,
`birthday` date NOT NULL,
`type` int(1) NOT NULL,
`registered` int(1) NOT NULL,
`phone` varchar(15) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `face_uid` (`face_uid`),
UNIQUE KEY `email` (`email`)
) ENGINE=INNODB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;