再说得详细一点:
程序内容:
$sql = 'INSERT INTO `serviceonline` (`Unit`, `Type`, `UserID`, `Title`, `Content`)
VALUES (:unit, :type, :userID, :title, :content)';
$dataConn->prepareSQL($sql, 'bindParam',
  array(':unit',    $u),
  array(':type',    $t),
  array(':userID',  $userID),
  array(':title',   $speechTitle, PDO::PARAM_STR),
  array(':content', $content,     PDO::PARAM_STR));用到的函数代码:
public function prepareSQL($sql, $bindFunctionName = '') {
    if (defined('DEBUG') && DEBUG) {
echo SQLConnAlert::COMMANDLINE . $sql;
    }
    self::$rsObj = parent::prepare($sql);
    if (!empty($bindFunctionName)) {
$bindArray = func_get_args(); // 获取全部参数
array_shift($bindArray); // 去掉开始的两个参数
array_shift($bindArray);
// 遍历参数数组, 进行参数绑定
foreach ($bindArray as $key => $value) {
    if (is_array($value)) { // 当前参数是数组时的处理
$bindKey    = $value[0];
$bindValue  = $value[1];
if (isset($value[3])) {
    self::$rsObj->$bindFunctionName($bindKey, $bindValue, $value[2], $value[3]);
} elseif (isset($value[2])) {
    self::$rsObj->$bindFunctionName($bindKey, $bindValue, $value[2]);
} else {
    self::$rsObj->$bindFunctionName($bindKey, $bindValue);
}
    } else {// 当前参数不是数组的处理
$bindKey   = $key + 1;
$bindValue = $value;
self::$rsObj->$bindFunctionName($bindKey, $bindValue);
    }
}
    }
    try {
$this->beginTransaction();
self::$rsObj->execute();
$this->commit();
    } catch (Exception $e) {
$this->rollBack();
    }
}

解决方案 »

  1.   

    $dataConn->prepareSQL($sql, 'bindParam', 
      array(':unit',    $u), 
      array(':type',    $t), 
      array(':userID',  $userID), 
    ---------------------------------------------------
      array(':title',  $speechTitle, PDO::PARAM_STR), 
      array(':content', $content,    PDO::PARAM_STR)); $dataConn->prepareSQL($sql, 'bindParam', 
      array(':unit',    $u), 
      array(':type',    $t), 
      array(':userID',  $userID, PDO::PARAM_INT), 
    -----------------------------------------------------
      array(':title',  $speechTitle, PDO::PARAM_STR), 
      array(':content', $content,    PDO::PARAM_STR)); 试试上面的改动!PHP5.2.6里面要正确指定参数类型!默认是PdO::PARAM_STR
      

  2.   

    首先谢谢qngzh,我有前三个参数都是整数,我按你所说全部改了,可还是不行。
      

  3.   

    但如果不使用参数绑定,而是直接执行SQL命令就可以插入数据。
    $sql = "INSERT INTO `serviceonline` (`Unit`, `Type`, `UserID`, `Title`, `Content`)
    VALUES ($u, $t, $userID, '$speechTitle', '$content')";
    $dataConn->prepareSQL($sql);
    这样使用就没有任何问题,不知是什么原因?
    肯请各位达人说明之。
      

  4.   

    把PDO::ATTR_ERRMODE设置为抛出异常再看看错误信息!!!
      

  5.   

    谢谢你,你的建议很有指导性,但还是不行,我不明白问题所在,这是我提交的数据$u = 1 $t= 4 $userID = 1 $speechTitle = 'd' $content = 'ee'这是我提交后的提示数据库查询命令:INSERT INTO `serviceonline` (`Unit`, `Type`, `UserID`, `Title`, `Content`) VALUES (:unit, :type, :userID, :title, :content)
    绑定代码:self::$rsObj->bindParam(:unit, 1, 1)
    绑定代码:self::$rsObj->bindParam(:type, 4, 1)
    绑定代码:self::$rsObj->bindParam(:userID, 1, 1)
    绑定代码:self::$rsObj->bindParam(:title, d, 2)
    绑定代码:self::$rsObj->bindParam(:content, ee, 2)
    批事务处理失败: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'ee' for column 'Unit' at row 1
      

  6.   

    从提示来看,我的数据绑定是完全正确的,可不知道为什么提示数据'ee'和字段'Unit'错误呢。
      

  7.   

    把参数设置为bindValue成功,说不太清楚什么原因,一开始我也曾这样用过,但没有成功,不过还好,现在可以用了,谢谢我的朋友“一起灌水吧”