PHP Mysql PDO 绑定变量数量与令牌数量不匹配
我环顾四周,但似乎无法找到我的问题的答案.
这是我第一次使用 PDO,所以我完全是新手.
我将大量数据拆分为 2 个表并希望将它们合并为一个,还有其他方法可以做到这一点,但没有深入探讨为什么我要这样做的复杂原因...>
我生成了我想从中复制数据的表的记录集
构建我的语句
循环运行
但我收到以下错误
SQLSTATE[HY093]: Invalid parameter number: number of bound variables not match of tokens
我已经通过并三重检查了我有相同数量的变量,所以为什么令牌不匹配我不知道"就像我说的那样对此很陌生,所以可能错过了专业人士认为显而易见的东西.
可能值得一提的是,我没有添加到表中的每一列,还有其他列,但我已将它们排除在准备好的语句之外...这是我的代码:
//$dbh = new PDO($hostname_Seriously, $DB_USER, $DB_PASSWORD);$dbh = new PDO('mysql:host=localhost;dbname=seriouslysoulful_summers', $username_Seriously, $password_Seriously);$stmt = $dbh->prepare("INSERT INTO records_rec (oldid_rec, firstname_rec,artist_rec,side_rec,bside_rec,label_rec,condition_rec,genere_rec,price_rec,collection_rec,active_rec,info_rec,notes_rec,order_rec,alabelimage_rec,asound_rec_rec,b、featured_rec、format_rec)VALUES (:oldid_rec, :firstname_rec, :artist_rec, :aside_rec, :bside_rec, :label_rec, :condition_rec, :genere_rec, :price_rec, :collection_rec, :active_rec, :info_rec, :notes_rec, :order_image_rec_recasound_rec, bsound_rec, :featured_rec, :format_rec)");$stmt->bindParam(':oldid_rec', $id);$stmt->bindParam(':firstname_rec', $firstname);$stmt->bindParam(':artist_rec', $artist);$stmt->bindParam(':aside_rec',$aside);$stmt->bindParam(':bside_rec',$bside);$stmt->bindParam(':label_rec',$label);$stmt->bindParam(':condition_rec',$condition);$stmt->bindParam(':genere_rec',$genere);$stmt->bindParam(':price_rec',$price);$stmt->bindParam(':collection_rec',$collection);$stmt->bindParam(':active_rec',$active);$stmt->bindParam(':info_rec',$info);$stmt->bindParam(':notes_rec',$notes);$stmt->bindParam(':order_rec',$order);$stmt->bindParam(':alabelimage_rec',$alabel);$stmt->bindParam(':blabelimage_rec',$blabel);$stmt->bindParam(':asound_rec',$asound);$stmt->bindParam(':bsound_rec',$bsound);$stmt->bindParam(':featured_rec',$featured);$stmt->bindParam(':format_rec',$format);$reccount = 0;//做{$id = $row_rs_original['id_prod'];$名字=mysql_real_escape_string($row_rs_original['firstname_prod']);$artist = mysql_real_escape_string($row_rs_original['artist_prod']);$aside = mysql_real_escape_string($row_rs_original['a_side_prod']);$bside = mysql_real_escape_string($row_rs_original['b_side_prod']);$label = mysql_real_escape_string($row_rs_original['label_prod']);$condition = mysql_real_escape_string($row_rs_original['condition_prod']);$genere = $row_rs_original['genre_prod'];$price = $row_rs_original['price_prod'];$collection = mysql_real_escape_string($row_rs_original['collection_prod']);$active = $row_rs_original['active_prod'];$info = mysql_real_escape_string($row_rs_original['info_prod']);$notes = mysql_real_escape_string($row_rs_original['notes_prod']);$order = $row_rs_original['order_prod'];$alabel = mysql_real_escape_string($row_rs_original['labelimage_A_prod']);$blabel = mysql_real_escape_string($row_rs_original['labelimage_B_prod']);$asound = mysql_real_escape_string($row_rs_original['soundfile_A_prod']);$bsound = mysql_real_escape_string($row_rs_original['soundfile_B_prod']);$featured = $row_rs_original['featured_prod'];$format = $row_rs_original['format_prod'];$stmt->execute();$reccount = $reccount +1;//} while ($row_rs_original = mysql_fetch_assoc($rs_original));echo($reccount." - 记录添加...");
缺少冒号
:blabelimage_rec, **:**asound_rec, **:**bsound_rec, :featured_rec, :format_rec
I've looked around here but can't seem to find an answer to my problem.
This is the first time I've used PDO and so am a complete newbie to it.
I have a load of data split into 2 tables and want to merge them into one, there are other ways of doing this, but without going into the complicated reasons why I am trying to do it this way...
I generate a recordset of the table I want to copy data from
construct my statement
run it in a loop
but I get the following error
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match the number of tokens
I've gone through and triple checked I have the same amount of variables so why "tokens don't match I dont know" like I said am very new to this so am probably missing something the pros would consider as obvious.
It's probably worth mentioning that I am not adding to every single column in the table, there are other columns but I have left them out of the prepared statement... Heres my code:
//$dbh = new PDO($hostname_Seriously, $DB_USER, $DB_PASSWORD); $dbh = new PDO('mysql:host=localhost;dbname=seriouslysoulful_summers', $username_Seriously, $password_Seriously); $stmt = $dbh->prepare("INSERT INTO records_rec (oldid_rec, firstname_rec, artist_rec, aside_rec, bside_rec, label_rec, condition_rec, genere_rec, price_rec, collection_rec, active_rec, info_rec, notes_rec, order_rec, alabelimage_rec, blabelimage_rec, asound_rec, bsound_rec, featured_rec, format_rec) VALUES (:oldid_rec, :firstname_rec, :artist_rec, :aside_rec, :bside_rec, :label_rec, :condition_rec, :genere_rec, :price_rec, :collection_rec, :active_rec, :info_rec, :notes_rec, :order_rec, :alabelimage_rec, :blabelimage_rec, asound_rec, bsound_rec, :featured_rec, :format_rec)"); $stmt->bindParam(':oldid_rec', $id); $stmt->bindParam(':firstname_rec', $firstname); $stmt->bindParam(':artist_rec', $artist); $stmt->bindParam(':aside_rec',$aside); $stmt->bindParam(':bside_rec',$bside); $stmt->bindParam(':label_rec',$label); $stmt->bindParam(':condition_rec',$condition); $stmt->bindParam(':genere_rec',$genere); $stmt->bindParam(':price_rec',$price); $stmt->bindParam(':collection_rec',$collection); $stmt->bindParam(':active_rec',$active); $stmt->bindParam(':info_rec',$info); $stmt->bindParam(':notes_rec',$notes); $stmt->bindParam(':order_rec',$order); $stmt->bindParam(':alabelimage_rec',$alabel); $stmt->bindParam(':blabelimage_rec',$blabel); $stmt->bindParam(':asound_rec',$asound); $stmt->bindParam(':bsound_rec',$bsound); $stmt->bindParam(':featured_rec',$featured); $stmt->bindParam(':format_rec',$format); $reccount = 0; //do{ $id = $row_rs_original['id_prod']; $firstname = mysql_real_escape_string($row_rs_original['firstname_prod']); $artist = mysql_real_escape_string($row_rs_original['artist_prod']); $aside = mysql_real_escape_string($row_rs_original['a_side_prod']); $bside = mysql_real_escape_string($row_rs_original['b_side_prod']); $label = mysql_real_escape_string($row_rs_original['label_prod']); $condition = mysql_real_escape_string($row_rs_original['condition_prod']); $genere = $row_rs_original['genre_prod']; $price = $row_rs_original['price_prod']; $collection = mysql_real_escape_string($row_rs_original['collection_prod']); $active = $row_rs_original['active_prod']; $info = mysql_real_escape_string($row_rs_original['info_prod']); $notes = mysql_real_escape_string($row_rs_original['notes_prod']); $order = $row_rs_original['order_prod']; $alabel = mysql_real_escape_string($row_rs_original['labelimage_A_prod']); $blabel = mysql_real_escape_string($row_rs_original['labelimage_B_prod']); $asound = mysql_real_escape_string($row_rs_original['soundfile_A_prod']); $bsound = mysql_real_escape_string($row_rs_original['soundfile_B_prod']); $featured = $row_rs_original['featured_prod']; $format = $row_rs_original['format_prod']; $stmt->execute(); $reccount = $reccount +1; //} while ($row_rs_original = mysql_fetch_assoc($rs_original)); echo($reccount." - records added...");
Missing colons
:blabelimage_rec, **:**asound_rec, **:**bsound_rec, :featured_rec, :format_rec
相关文章