php PDO调用带有out参数的存储过程(原创)

WBOY
Release: 2016-06-23 13:22:08
Original
1259 people have browsed it

这几天比较闲学了下PHP, 开发工具zendphp,server下的一个集成工具WampServer。 感觉php实现一个功能写的代码比asp.net java都少,特别是数据库访问这块,如果是asp.net或则java还得自己去封装一个类。当然php也可以封装但是大多是以前访问数据库的旧方式基础上封装,我这块用的好像是PHP数据库访问最新的一种技术 POD,所以不封装,代码也写得很少。 下面我将贴出我的代码,由于是新手如果写得不对不好希望看者别见笑。

代码部分:

<?php $dsn = "mysql:host=localhost;dbname=mysqldatabasedemo"; $db = new PDO($dsn,'root','123456@#',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET   NAMES'GBK';"));  $someInParameter1='hellow';  $stmt = $db->prepare("CALL outputProcudure(:addName,@outASD)");  $stmt->bindParam(':addName', $someInParameter1);   if($stmt->execute())   {      $rs=$db->query('select @outASD')->fetchAll();      $dataArray=$rs[0];      echo("<script type='text/javascript'> alert('"+$dataArray[0]+"');</script>");   }   else   {    echo("<script type='text/javascript'> alert('插入失败');</script>");   } ?>
Copy after login

  

mysql存储过程:

  

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template