duanlijia5864 2016-05-20 06:13
浏览 45
已采纳

如何在PHP PDO中创建函数插入

I had a problem when making the insert function with bindParam or bindValue, always error like this: enter image description here

what should be improved from my code :

<?php

function IUD($sql, $param = array()){ 

global $koneksi;

$stmt = $koneksi->prepare($sql);

foreach ($param as $key => $value) {
if(is_int($value)){
$stmt->bindParam("$key", $value, PDO::PARAM_INT);
}else{
$stmt->bindParam("$key", $value);
}
}

$ret = $stmt->execute();
}

$insert = IUD("INSERT INTO user (nama_lengkap,username,password,type_user,foto,tgl) VALUES(:nm,:user,:pass,:type,:foto,:tgl)", array(':nm'=>$nm,':user'=>$user,'pass:'=>$pass,':type'=>$type,':foto'=>$foto,'tgl'=>$tgl));

?>
  • 写回答

1条回答 默认 最新

  • dssqq82402 2016-05-20 06:17
    关注

    You had a typo, that's all. You should have:

    ':tgl' => $tgl
    

    In your query $params array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题