php动态绑定变量的用法
2015-06-16 00:00
591 查看
本文实例讲述了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生成plist数据的方法
- 分享php分页的功能模块
- php采集中国代理服务器网的方法
- PHP限制HTML内容中图片必须是本站的方法
- PHP处理postfix邮件内容的方法
- Sublime Text 插件推荐系列 —— 用 Sublime 开发 Laravel
- Yii2:推荐一个方法arrayHelper::map()
- PHP 7 编译过程记录
- PHP 匿名函数的探索
- PHP $this->方法调用
- PHP基础知识
- PHP面向对象基础概念(抽象方法和抽象类)
- PHP扩展
- php 什么是变量?
- composer update 报The .git directory is missing from XXX
- 使用phpmyadmin的界面为MySQL添加外键
- 还是PHPExcel问题
- PHP中 类的访问控制
- php实现上传图片保存到数据库的方法
- PHP 中加载类文件的几种方法