再说得详细一点:
程序内容:
$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();
}
}
程序内容:
$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();
}
}
解决方案 »
- apache下的.htaccess文件的301重定向问题
- <?php只有开头没有结尾?
- php不能存带时间的cookies
- 数据批量选取,批量数据操作!!!
- 怎样通过URL把参数传递给下一个页面
- 再次请教各位高手,有谁知道,如何用PHP向sybase和oracle数据库中提交word文档???
- 请问include 和 require的区别?
- speedphp :一次性将网站类的地址改为绝对地址
- thinkphp uploadify图片上传后表单提交 这个流程应该怎么设计
- php树形结构显示
- 祝福兼散分兼问问题
- php 的三元操作符,怎么样控制输出,就是说:如果是1输出一个"是"字,如果是0输出一个'否'字
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
$sql = "INSERT INTO `serviceonline` (`Unit`, `Type`, `UserID`, `Title`, `Content`)
VALUES ($u, $t, $userID, '$speechTitle', '$content')";
$dataConn->prepareSQL($sql);
这样使用就没有任何问题,不知是什么原因?
肯请各位达人说明之。
绑定代码: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