php动态绑定变量的用法


Posted in PHP onJune 16, 2015

本文实例讲述了php动态绑定变量的用法。分享给大家供大家参考。具体如下:

private function bindVars($stmt,$params) {
  if ($params != null) {
    $types = ''; //initial sting with types
    foreach($params as $param) {
 //for each element, determine type and add
      if(is_int($param)) {
        $types .= 'i'; //integer
      } elseif (is_float($param)) {
        $types .= 'd'; //double
      } elseif (is_string($param)) {
        $types .= 's'; //string
      } else {
        $types .= 'b';
 //blob and unknown
      }
    }
    $bind_names[] = $types;
 //first param needed is the type string
 // eg: 'issss'
    for ($i=0; $i<count($params);$i++) {
 //go through incoming params and added em to array
      $bind_name = 'bind' . $i;
   //give them an arbitrary name
      $$bind_name = $params[$i];
   //add the parameter to the variable variable
      $bind_names[] = &$$bind_name;
   //now associate the variable as an element in an array
    }
    //call the function bind_param with dynamic params
    call_user_func_array(array($stmt,'bind_param'),$bind_names);
  }
  return $stmt; //return the bound statement

希望本文所述对大家的php程序设计有所帮助。

PHP 相关文章推荐
黑夜路人出的几道php笔试题
Aug 04 PHP
PHP结合JQueryJcrop实现图片裁切实例详解
Jul 24 PHP
PHP统一页面编码避免乱码问题
Apr 09 PHP
JavaScript实现滚动栏效果的方法
Apr 27 PHP
php类的定义与继承用法实例
Jul 07 PHP
PHP截取IE浏览器并缩小原图的方法
Mar 04 PHP
PHP 中提示undefined index如何解决(多种方法)
Mar 16 PHP
PHP控制前台弹出对话框的实现方法
Aug 21 PHP
php Session无效分析资料整理
Nov 29 PHP
kindeditor 加入七牛云上传的实例讲解
Nov 12 PHP
PHP设计模式之模板方法模式定义与用法详解
Apr 02 PHP
PHP生成短网址的思路以及实现方法的详解
Mar 25 PHP
php实现在服务器端调整图片大小的方法
Jun 16 #PHP
PHP正则验证Email的方法
Jun 15 #PHP
PHP实现通过正则表达式替换回调的内容标签
Jun 15 #PHP
PHP检测用户语言的方法
Jun 15 #PHP
php实现求相对时间函数
Jun 15 #PHP
php数组随机排序实现方法
Jun 13 #PHP
隐性调用php程序的方法
Jun 13 #PHP
You might like
备份mysql数据库的php代码(一个表一个文件)
2010/05/28 PHP
PHP list() 将数组中的值赋给变量的简单实例
2016/06/13 PHP
扩展String功能方法
2006/09/22 Javascript
我见过最全的个人js加解密功能页面
2007/12/12 Javascript
一些mootools的学习资源
2010/02/07 Javascript
javascript 中that的含义示例介绍
2014/05/14 Javascript
判断字符串的长度(优化版)中文占两个字符
2014/10/30 Javascript
Javascript实现单张图片浏览
2014/12/18 Javascript
JavaScript中遍历对象的property的3种方法介绍
2014/12/30 Javascript
jQuery知识点整理
2015/01/30 Javascript
js鼠标单击和双击事件冲突问题的快速解决方法
2016/07/11 Javascript
jQuery实现弹窗下底部页面禁止滑动效果
2017/12/19 jQuery
使用Angular CLI快速创建Angular项目的一些基本概念和写法小结
2018/04/22 Javascript
nodejs遍历文件夹下并操作HTML/CSS/JS/PNG/JPG的方法
2018/11/01 NodeJs
vue2.x 对象劫持的原理实现
2020/04/19 Javascript
详解vue v-model
2020/08/31 Javascript
django 自定义用户user模型的三种方法
2014/11/18 Python
Python实现将一个大文件按段落分隔为多个小文件的简单操作方法
2017/04/17 Python
python实现名片管理系统
2018/11/29 Python
详解Python的循环结构知识点
2019/05/20 Python
Python使用百度翻译开发平台实现英文翻译为中文功能示例
2019/08/08 Python
python 3.6.7实现端口扫描器
2019/09/04 Python
使用Python绘制台风轨迹图的示例代码
2020/09/21 Python
python模拟点击玩游戏的实例讲解
2020/11/26 Python
CSS3中的5个有趣的新技术
2009/04/02 HTML / CSS
HTML5 canvas实现雪花飘落特效
2016/03/08 HTML / CSS
HTML5 CSS3打造相册效果附源码下载
2014/06/16 HTML / CSS
英国品牌男装折扣网站:Brown Bag
2018/03/08 全球购物
JRE、JDK、JVM之间的关系怎样
2012/05/16 面试题
蛋糕店的商业计划书范文
2014/01/27 职场文书
行政求职信
2014/07/04 职场文书
端午节活动总结
2014/08/26 职场文书
刑事附带民事上诉状
2015/05/23 职场文书
幼儿园开学家长寄语(2016秋季)
2015/12/03 职场文书
2016年圣诞节寄语(一句话)
2015/12/07 职场文书
Oracle更换为MySQL遇到的问题及解决
2021/05/21 Oracle