duanlao6573 2013-12-20 20:53
浏览 47

PDO mysql错误

I am currently working on a project for a client but because I am new to pdo I have no clue how to hand the error it keeps spitting out. The code I am working with is not mine either, so that adds a bit of confusion to the mix. It keeps telling me:

Query failed: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server 
version for the right syntax to use near '' at line 1

I have narrowed down the error to these lines:

$regid = $dbh->lastInsertId('');

$dupsid = true;
while ($dupsid){
    srand((double)microtime()*1000000);
    $maxrand = 100000000;
    $rand_sid = rand();
    $check_sid = "select reguniqid from v_events_registrants where reguniqid = :RAND_SID";
    $stmt = $dbh->prepare($check_sid);
    $stmt->bindValue(':RAND_SID', $rand_sid);
    $stmt->execute();

    $num_result = $stmt->rowCount();
    if ($num_result == 0) $dupsid = false;
}

$uniqid_upd = "update v_events_registrants set reguniqid = :RAND_SID where registrant_id = :REGID";
$stmt = $dbh->prepare($uniqid_upd);
$stmt->bindValue(':RAND_SID', $rand_sid);
$stmt->bindValue(':REGID', $regid);
$stmt->execute();

in this case here $reg is the primary key of the table in which the last few items were added. Initially I thought that was the issue but when I cleared it of ', and " I get an invalid id error, which I am guessing is from the next execution of the pdo. Please help as this error is really starting to hold me back from completing this project for my client.

  • 写回答

4条回答 默认 最新

  • douyan8413 2013-12-20 20:59
    关注

    Your first line defines $reg, then you try to use the undefined $regid

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题