需要您的帮助。PHP数组到MySQL BD ...缺少数组字段
我需要更新mysql表中的数组数据。我的问题是,有一些数组值没有“照片”coloum(检查数组中的第四个字段),因为我的查询失败,出现错误“列计数与第1行的值计数不匹配” 下面是什么我尝试着。
$dept = $job->user();
$sql = array();
foreach($dept as $row) {
$sql[] = '('.$row['dob'].', "'.($row['name']).'", "'.($row['role']).'"
"'.$row['email'].'", "'.($row['photo']).'")';
}
mysql_query('INSERT INTO cast (dob, name, role, email, photo) VALUES '.implode(',', $sql)) or die(mysql_error());
阵列数据
array
0 =>
array
'dob' => string '01121978'
'name' => string 'Ram Avtar'
'role' => string 'Inspector'
'email' => string '[email protected]'
'photo' => string ' '
1 =>
array
'dob' => string '15021978'
'name' => string 'Suresh Babu'
'role' => string 'Constable'
'email' => string '[email protected]'
'photo' => string ' '
2 =>
array
'dob' => string '11111965'
'name' => string 'Dean'
'role' => string 'Inspector'
'email' => string '[email protected]'
'photo' => string ' '
3 =>
array
'dob' => string '10061979'
'name' => string 'Rohit Shette'
'role' => string 'Sergeant'
'email' => string ' '
'photo' => string ' '
4 =>
array
'dob' => string '15081979'
'name' => string 'Ian'
'role' => string 'warden'
'email' => string ' '
表结构
CREATE TABLE user(
id INT(5) NOT NULL AUTO_INCREMENT,
dob TEXT NOT NULL,
name TEXT NOT NULL,
role TEXT DEFAULT NULL,
email TEXT DEFAULT NULL,
photo TEXT DEFAULT NULL
)
ENGINE = INNODB
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
你能证明你的真实所产生的SQL,PHP不产生呢? – zerkms 2012-01-08 22:11:59