prepare("select id,ztname,zttype,zttime,headimg,riseimg "/> prepare("select id,ztname,zttype,zttime,headimg,riseimg ">

Rumah >pembangunan bahagian belakang >tutorial php > 怎么在function里操作pdo呀

怎么在function里操作pdo呀

WBOY
WBOYasal
2016-06-13 12:30:19906semak imbas

如何在function里操作pdo呀
代码如下

require("../inc/pdo.php");<br />
<br />
function output($action,$select,$name){<br />
$select=$dbc->prepare("select id,ztname,zttype,zttime,headimg,riseimg from naszt where 1=1 and zttype=:zttype");<br />
$select->bindValue(":zttype",$action);<br />
$select->execute();<br />
$result='';<br />
while($row=$select->fetch()){<br />
$result.='<ul id="thumbs"><li class="'.$name.'">';<br />
$result.='<div class="img-container">';<br />
$result.='<div class="item-img">';<br />
$result.='<img  src="ztImg/'.$row['riseimg'].'"   style="max-width:90%" 怎么在function里操作pdo呀 " ></div><ul>';<br />
$result.='<li><a href="portfolio-single.html" class="view">测试1</a></li>';<br />
$result.='<li><a href='.$row['headimg'].' class="preview" data-rel="prettyPhoto[web]">测试12</a></li></ul></div><div class="item-info">';<br />
$result.='<h3 class="title">'.$row['ztname'].'</h3>';<br />
$result.='<span class="category">'. $row['zttype'].'</span>';	<br />
$result.='<p class="intro">1推荐日期:'.$row['zttime'].'</p></div></li>';<br />
	}<br />
return $result;<br />
}


<?php<br />
header("Content-Type:text/html;charset=utf-8");<br />
$dbtype='mysql';<br />
$host='127.0.0.1';<br />
$dbName='nas';<br />
$user='227227';<br />
$pass='227227';<br />
$db="$dbtype:host=$host;dbname=$dbName";<br />
try{<br />
$dbc=new PDO($db,$user,$pass);<br />
$dbc->exec('SET CHARACTER SET utf8');<br />
$dbc->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //禁用prepared statements的仿真<br />
	}catch(PDOException $e){<br />
echo $e->getMessage();<br />
}<br />
?>


我想在function调用pdo 
是不是在pdo里面写class  function要继承这个类?

求大神出手指点该如何写!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn