pdo 调用mysql 存储过程
$stmt = $dbh->prepare("CALL test(:bb)");
$aa = '';
$stmt->bindParam(':bb', $aa, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
var_dump($stmt->execute());
var_dump($aa);
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
$stmt = $dbh->prepare("select * from userinfo where u_id=:id");
$aa = 1;
$stmt->bindParam(':id', $aa, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
var_dump($stmt->execute());
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
下面是来自其它网站的一款php 引用 & 使用教程哦,我现在把它发布过来给各位朋友看看吧,适合于php初学者哦,php &
下面是来自其它网站的一款php 引用 & 使用教程哦,我现在把它发布过来给各位朋友看看吧,适合于php初学者哦,php &
PHP 的引用允许你用两个变量来指向同一个内容
PHP代码:
<?
$a="ABC";
$b =&$a;
echo $a;//这里输出:ABC
echo $b;//这里输出:ABC
$b="EFG";
echo $a;//这里$a的值变为EFG 所以输出EFG
echo $b;//这里输出EFG
?>
函数的传址调用
传址调用我就不多说了 下面直接给出代码
PHP代码:
function test(&$a)
{
$a=$a+100;
}
$b=1;
echo $b;//输出1
test($b); //这里$b传递给函数的其实是$b的变量内容所处的内存地址,通过在函数里改变$a的值 就可以改变$b的值了
echo "<br>";
echo $b;//输出101
要注意的是,在这里test(1);的话就会出错,原因自己去想
函数的引用返回
先看代码
PHP代码:
function &test()
{
static $b=0;//申明一个静态变量
$b=$b+1;
echo $b;
return $b;
}
$a=test();//这条语句会输出 $b的值 为1
$a=5;
$a=test();//这条语句会输出 $b的值 为2
$a=&test();//这条语句会输出 $b的值 为3
$a=5;
$a=test();//这条语句会输出 $b的值 为6
下面解释下:
通过这种方式$a=test();得到的其实不是函数的引用返回,这跟普通的函数调用没有区别 至于原因: 这是PHP的规定
PHP规定通过$a=&test(); 方式得到的才是函数的引用返回
至于什么是引用返回呢(PHP手册上说:引用返回用在当想用函数找到引用应该被绑定在哪一个变量上面时。) 这句狗屁话 害我半天没看懂
用上面的例子来解释就是
$a=test()方式调用函数,只是将函数的值赋给$a而已, 而$a做任何改变 都不会影响到函数中的$b
而通过$a=&test()方式调用函数呢, 他的作用是 将return $b中的 $b变量的内存地址与$a变量的内存地址 指向了同一个地方
即产生了相当于这样的效果($a=&b;) 所以改变$a的值 也同时改变了$b的值 所以在执行了
$a=&test();
$a=5;
以后,$b的值变为了5
这里是为了让大家理解函数的引用返回才使用静态变量的,其实函数的引用返回多用在对象中
对象的引用
PHP代码:
<?
class a{
var $abc="ABC";
}
$b=new a;
$c=$b;
echo $b->abc;//这里输出ABC
echo $c->abc;//这里输出ABC
$b->abc="DEF";
echo $c->abc;//这里输出DEF
?>
以上代码是在PHP5中的运行效果
在PHP5中 对象的复制 是通过引用来实现的。上列中$b=new a; $c=$b; 其实等效于$b=new a; $c=&$b;
PHP5中默认就是通过引用来调用对象, 但有时你可能想建立一个对象的副本,并希望原来的对象的改变不影响到副本 . 为了这样的目的,PHP定义了一个特殊的方法,称为__clone.
引用的作用
如果程序比较大,引用同一个对象的变量比较多,并且希望用完该对象后手工清除它,个人建议用 "&" 方式,然后用$var=null的方式清除. 其它时候还是用php5的默认方式吧. 另外, php5中对于大数组的传递,建议用 "&" 方式, 毕竟节省内存空间使用。
取消引用
当你 unset 一个引用,只是断开了变量名和变量内容之间的绑定。这并不意味着变量内容被销毁了。例如:
<?php
$a = 1;
$b =& $a;
unset ($a);
?>
不会 unset $b,只是 $a。
global 引用
当用 global $var 声明一个变量时实际上建立了一个到全局变量的引用。也就是说和这样做是相同的:
<?php
$var =& $GLOBALS["var"];
?>
这意味着,例如,unset $var 不会 unset 全局变量。
$this
在一个对象的方法中,$this 永远是调用它的对象的引用。
//下面再来个小插曲
php中对于地址的指向(类似指针)功能不是由用户自己来实现的,是由Zend核心实现的,php中引用采用的是“写时拷贝”的原理,就是除非发生写操作,指向同一个地址的变量或者对象是不会被拷贝的。
通俗的讲
1:如果有下面的代码
PHP代码:
$a="ABC";
$b=$a;
其实此时 $a与$b都是指向同一内存地址 而并不是$a与$b占用不同的内存
2:如果在上面的代码基础上再加上如下代码
PHP代码:
$a="EFG";
由于$a与$b所指向的内存的数据要重新写一次了,此时Zend核心会自动判断 自动为$b生产一个$a的数据拷贝,重新申请一块内存进行存储
<option value="1">自定义天数</option>
<option value="d">查询昨日收录情况</option>
<option value="w">查询最近1星期收录情况</option>
<option value="m">查询最近1月收录情况</option>
<option value="m2">查询最近2月收录情况</option>
<option value="m3">查询最近3月收录情况</option>
<option value="m6">查询最近6月收录情况</option>
<option value="y">查询最近1年收录情况</option>
<option value="all">查询总的(所有日期)收录情况</option>
等信息。
function GetPage($url)
{
$buf=parse_url($url);
if($buf['scheme']=="http")//如果是URL
{
$host=$buf['host'];
$page=$buf['path'];
if(trim($buf['query'])!=="") $page.="?".trim($buf['query']);
$myHeader="GET $url HTTP/1.1rn";
$myHeader.="Host: $hostrn";
$myHeader.="Connection: closern";
$myHeader.="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5rn";
$myHeader.="Accept-Language: zh-cn,zh;q=0.5rn";
$myHeader.="Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7rn";
$myHeader.="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.7.6) Gecko/20050226 Firefox/1.0.1 Web-Sniffer/1.0.20rn";
$myHeader.="Referer: http://$host/rnrn";
$server=$host;
$port=80;
$res="";
if(false!==($fp = @fsockopen ($server, $port, $errno, $errstr, 30)))
{
@fputs ($fp, $myHeader);
while (!@feof($fp)) $res.= @fgets ($fp, 1024);
@fclose ($fp);
}
else return false;
if(strlen($res)==0) return false;
return $res;
}
else//如果是本地文件
{
$fileName=$url;
if(false!==@file_exists($fileName))
{
if(false!==($buf=@implode("",file($fileName)))&&@strlen($buf)>0)
{
return $buf;
}
else return false;
}
else return false;
}
}
function GetContent($str,$x,$y){
$tem=strstr($str,$x);
return substr($tem,0, strpos($tem,$y));
}
对取得的google信息进行分析并且在本地。
if (isset($q))
{
$TheUrl="http://www.google.cn/search?q=+site:".$q."&num=20&complete=1&hl=zh-CN&lr=&newwindow=1&as_qdr=".$t."&start=".$p."&sa=N";
$TheThie=GetPage($TheUrl);
}
$TheBody=GetContent($TheThie,"<div id=res class=med>","<div id=bsf style");
$TheBody=iconv( "UTF-8", "gb2312//IGNORE" , $TheBody);
$TheBody=str_replace("<!--z--><p><i>","<!--z--><!--<p><i>",$TheBody);
$TheBody=str_replace('<br clear="all"/>','<br clear="all"/>',$TheBody);
$TheBody=preg_replace('<a href="/search?num=20(.+?)amp;as_qdr=(.+?)&q=site:(.+?)&start=(.+?)&sa=N">','a href=?q=$3&t=$2&p=$4> <!--z--',$TheBody);
$TheBody=str_replace("该网站可能含有恶意软件,有可能会危害您的电脑。","",$TheBody);
$TheBody=str_replace("/interstitial?url=","",$TheBody);
$TheBody=str_replace("- <nobr>","",$TheBody);
$TheBody=str_replace("类似网页","",$TheBody);
$total=GetContent($TheThie,"</b></div><p>","</b> - <b>");
$total=iconv( "UTF-8", "gb2312//IGNORE" , $total);
$total=GetContent($total,"有 <b>","</b> 项");
$total=str_replace("有 <b>","",$total);
$total=str_replace(",","",$total);
$total=intval($total);
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
switch($imageType) {
case "image/gif":
$source=imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
switch($imageType) {
case "image/gif":
imagegif($newImage,$thumb_image_name);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newImage,$thumb_image_name,90);
break;
case "image/png":
case "image/x-png":
imagepng($newImage,$thumb_image_name);
break;
}
chmod($thumb_image_name, 0777);
return $thumb_image_name;
}
class TEMPLATE
{
private $path = "." ; #根目录
private $var;
private $tplDir = "template"; #模板存储目录
private $tplExt = "tpl"; #模板文件的后缀名
private $tplId = 0 ; #模板的ID号
private $compileDir = "template_c"; #编译后的php文件存放目录
private $isCache=false ; #是否用缓存 (默认不启动)
private $cacheId = 1; #缓存文件ID号
private $cacheLeftTime=3600; #缓存有效期 (默认保存3600秒)
private $cacheDir = "cache"; #缓存文件存储目录
private $autoRefresh = false ; #是否自动刷新
private $pattern = array(
"/({dw:)s*includes*filename=s*"(.+..+)s*"s*(/})/i",#包含文件
"/({dw:)s*field.(.+)s*(/})/i",#局部变量
"/({dw:)s*global.(.+)s*(/})/i",#全局变量
"/({dw:)s*foreachs*(.+)s*ass*(.+)s*(/})/i",#foreach 语句
"/({dw:)s*ends*foreachs*(/})/i", #foreach 结束
"/({dw:)s*ifs*((.+))(/})/i",
"/({dw:)s*elseifs*((.+))(/})/i",
"/({dw:)s*elses*(/})/i",
"/({dw:)s*ends*ifs*(/})/i",
);
private $replacement = array(
'<?php echo $this->inc_file("\2"); ?>',
"<?php echo $\2;?>",
"<?php global $\2;n echo $\2; ?>",
"<?php foreach($\2 as $\3){ ?>",
"<?php } ?>",
"<?php if (\2) { ?>" ,
"<?php }else if(\2){ ?>",
"<?php }else{ ?>",
"<?php } ?>",
);
#构造函数
function __construct($path = "", $tplDir="", $compileDir="",$isCache="",$cacheLeftTime="",$cacheDir="" ,$autoRefresh="")
{
$this->path = $path ? $path : $this->path ;
$this->tplDir = $tplDir ? $tplDir : $this->tplDir ;
$this->compileDir = $compileDir ? $compileDir : $this->compileDir ;
$this->isCache = is_bool($isCache) ? $isCache : $this->isCache ;
$this->cacheLeftTime = $cacheLeftTime ? $cacheLeftTime : $this->cacheLeftTime ;
$this->cacheDir = $cacheDir ? $cacheDir : $this->cacheDir ;
$this->autoRefresh = is_bool($autoRefresh) ? $autoRefresh : $this->autoRefresh ;
}
#兼容php4
function TEMPLATE($path = "", $tplDir="", $compileDir="",$isCache="",$cacheLeftTime="",$cacheDir="" ,$autoRefresh="")
{
$this->__construct($path = "", $tplDir="", $compileDir="",$isCache="",$cacheLeftTime="",$cacheDir="" ,$autoRefresh="");
}
function __get($property)
{
return $this->$property ;
}
function __set($property,$value)
{
return $this->$property = $value ;
}
#给模板中的变量赋值
# $tplVal 模板中的变量名
function assign($tplVal ,$value="")
{
if (is_array($tplVal))
{
foreach ($tplVal as $key => $val)
{
if (!empty($key))
$this->var[$key] = $val ;
}
}
else {
if (!empty($tplVal))
$this->var[$tplVal] = $value ;
}
}
#输出文件内容函数
function display($tplFile,$tplId=0,$cacheId = 1,$cacheLeftTime="")
{
if (empty($tplFile)) die("Template "{$tplFile}" not exist !");
$this->cacheId = $cacheId ? md5($cacheId) : md5($this->cacheId);
$cacheFile = $this->path. "/".$this->cacheDir."/".$tplFile.$this->cacheId ;
if ($this->check_cache($cacheFile,$cacheLeftTime)) #当缓存文件存在且不过期时直接从缓存文件读取内容
{
echo $this->read_file($cacheFile);
}else {
$tpl = $this->path."/".$this->tplDir."/".$tplFile.".".$this->tplExt;
$tplContent = $this->read_file($tpl); #读取模板文件的内容
$compileContent= $this->compile_file($tplContent); #对读取出来的文件进行编译
$this->tplId = $tplId ? $tplId : $this->tplId ;
$compileFile = $this->path."/".$this->compileDir."/".md5($this->tplId)."".$tplFile.".php";
$this->write_file($compileFile,$compileContent);#将编译后的内容写入相应的文件中;
@extract($this->var);
ob_start();
include_once($compileFile);
$content = ob_get_contents() ;
ob_end_clean() ;
if ($this->isCache){
$this->write_file($cacheFile,$content) ;# 帮编译好的内容写入缓存文件
}
echo $content ;
}
}
/* function trim_tag($content)
{
$content = str_replace($this->startTag,"",$content);
$content = str_replace($this->endTag,"",$content);
//$content = trim($content);
return $content ;
}*/
# 编译文件函数
function compile_file($content=null)
{
$content = $content ? $content :die("Compile fail!") ;
//$content = $this->trim_tag($content);
$content = preg_replace($this->pattern,$this->replacement,$content);
return $content;
}
#解析包含文件
function inc_file($filename,$tplId="",$cacheId="",$cacheLeftTime="")
{
$file = $this->path."/".$this->tplDir."/".$filename ;
if (file_exists($file))
{
$filename = str_replace(".".$this->tplExt,"",$filename);
return $this->display($filename,$tplId,$cacheId,$cacheLeftTime);
}
else die("Template "{$filename}" not exist");
}
#读取文件内容函数
function read_file($filename)
{
if (!file_exists($filename)) die("Read file fail") ;
return file_get_contents($filename);
}
#内容写入函数
function write_file($filename,$content,$mode="wb")
{
$filename = trim($filename);
$content = $content ? stripslashes(trim($content)) : exit();
if (!file_exists($filename))
{
$array = explode("/",$filename);
$count = count($array);
$path = "";
for ($i = 0 ; $i <$count-1 ; ++$i )
{
if(!file_exists($path .= $array[$i]."/"))
{
mkdir($path,0777);
}
}
}
$handle = fopen($filename,$mode) ;
fwrite($handle,$content);
fclose($handle);
return true;
}
# 清除缓存
function clear_dir($dir="")
{
$dir = $this->path."/".$dir;
$handle = opendir($dir);
if (file_exists($dir))
{
while ($file = readdir($handle))
{
if ($file !="." && $file != "..")
unlink($dir."/".$file);
}
closedir($handle);
return true;
}
else {
return false;
}
}
#清除所有缓存
function clear_all_cache()
{
if ($this->clear_dir($this->cacheDir) && $this->clear_dir($this->compileDir))
return true;
}
#检查缓存是否过期
function check_cache($cacheFile,$cacheLeftTime="")
{
$cacheLeftTime = $cacheLeftTime ? $cacheLeftTime : $this->cacheLeftTime;
if (!file_exists($cacheFile)) return false ;
$time = $this->get_time($cacheFile) + $cacheLeftTime ;
if ($time <time())
{
unlink($cacheFile);
return false;
}
return true;
}
# 获取文件最后编辑时间
function get_time($filename)
{
if (!file_exists($filename)) return false;
return filemtime($filename);
}
}
相关文章
- Create Procedure AtoC @ChangeMoney Money as Set Nocount ON Declare @String1 char(20) Declare @String2 char(30) ...2016-11-25
- 这篇文章主要介绍了Spring AOP 对象内部方法间的嵌套调用方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-08-29
- 存储过程在数据库的应用中我们用到的非常的多了,下面我们来看一篇关于PHP操作MSSQL存储过程修改用户密码的例子,具体的如下所示。 mssql2008 存储过程 下面可以直接...2016-11-25
- 这篇文章主要介绍了Vue基于localStorage存储信息代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-16
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 这篇文章主要介绍了c# 三种方法调用WebService接口的相关资料,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-07
- 这篇文章主要介绍了js实现调用网络摄像头及常见错误处理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-07
- 这篇文章介绍了c#动态调用Webservice的两种方法实例,有需要的朋友可以参考一下...2020-06-25
- 具体详情请看下文小编给大家带来的知识点。同编写程序类似,存储过程中也有对应的条件判断,功能类似于if、switch。在MySql里面对应的是IF和CASE1、IF判断IF判断的格式是这样的:IF expression THEN commands [ELSEIF ex...2015-10-21
- 这篇文章主要给大家介绍了关于c#中的WebService及其调用方式的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
- 这篇文章主要介绍了解决Vue watch里调用方法的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-07
- 这篇文章主要介绍了解决vue watch数据的方法被调用了两次的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-07
- 下面小编就为大家带来一篇C#中加载dll并调用其函数的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 本文章来给大家详细介绍在php中如何来调用执行mysql存储过程然后返回由存储过程返回的值了,有需要了解的同学可进入参考。 。调用存储过程的方法。 a。如果存储过...2016-11-25
- 我们要明确,为什么要进行异步回调?众所周知,普通方法运行,是单线程的,如果中途有大型操作(如:读取大文件,大批量操作数据库,网络传输等),都会导致方法阻塞,表现在界面上就是,程序卡或者死掉,界面元素不动了,不响应了...2020-06-25
- 这篇文章主要介绍了C#调用python脚本的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
- 这篇文章主要介绍了javascript实现方法调用与方法触发小结的相关资料,需要的朋友可以参考下...2016-03-30
- 方法一:直接调用复制代码 代码如下:<? /******************************************************************************/ /* 文件名 : soapclient.php /* 说 明 : WebService接口客户端例程 /****************...2014-06-07
- 参考:http://stackoverflow.com/questions/412341/how-should-i-store-guid-in-mysql-tables通常用UUID做唯一标识,需要在数据库中进行存储。UUID的格式 复制代码 代码如下: String string = UUID.randomUUID().toStrin...2015-03-15
- 下面小编就为大家分享一篇基于C#调用c++Dll结构体数组指针的问题详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-06-25