PHP实现PDO操作mysql存储过程

发布时间:2024-06-10 点击:106
pdo一是php数据对象(php data object)的缩写。并不能使用pdo扩展本身执行任何数据库操作,必须使用一个database-specific pdo driver(针对特定数据库的pdo驱动)访问数据库服务器。pdo并不提供数据库抽象,它并不会重写sql或提供数据库本身缺失的功能,如果你需要这种功能,你需要使用一个更加成熟的抽象层。pdo需要php5核心oo特性的支持,所以它无法运行于之前的php版本。
本文实例讲述了php实现pdo操作mysql存储过程。分享给大家供大家参考,具体如下:
一 代码
sql语句:
create procedure pro_reg (in nc varchar(80), in pwd varchar(80), in email varchar(80),in address varchar(50)) begin insert into tb_reg (name, pwd ,email ,address) values (nc, pwd, email, address); end; index.php:
<!doctype html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=content-type content=text/html; charset=utf-8 /> <title>用户注册</title> <link rel=stylesheet type=text/css href=style.css rel=external nofollow > </head> <script language=javascript> function chkinput(form){ if(form.nc.value==){ alert(请输入用户昵称!); form.nc.select(); return(false); } if(form.pwd.value==){ alert(请输入注册密码!); form.pwd.select(); return(false); } if(form.email.value==){ alert(请输入e-mail地址!); form.email.select(); return(false); } if(form.address.value==){ alert(请输入家庭地址!); form.address.select(); return(false); } return(true); } </script> <body> <table width=200 border=0 align=center cellpadding=0 cellspacing=0> <tr> <td><img src=images/banner.gif width=500 height=65 /></td> </tr> </table> <table width=500 height=10 border=0 align=center cellpadding=0 cellspacing=0> <tr> <td></td> </tr> </table> <table width=500 border=0 align=center cellpadding=0 cellspacing=0> <tr> <td bgcolor=#1170ff><table width=500 height=157 border=0 align=center cellpadding=0 cellspacing=1> <form name=form1 method=post action=index.php onsubmit=return chkinput(this)> <tr> <td height=25 colspan=2 bgcolor=#b5d3ff><div align=center>用户注册</div></td> </tr> <tr> <td width=150 height=25 bgcolor=#ffffff><div align=center>用户昵称:</div></td> <td width=347 bgcolor=#ffffff>?<input type=text name=nc class=inputcss size=25></td> </tr> <tr> <td height=25 bgcolor=#ffffff><div align=center>注册密码:</div></td> <td height=25 bgcolor=#ffffff>?<input type=password name=pwd class=inputcss size=25></td> </tr> <tr> <td height=25 bgcolor=#ffffff><div align=center>e-mail:</div></td> <td height=25 bgcolor=#ffffff>?<input type=text name=email class=inputcss size=25></td> </tr> <tr> <td height=25 bgcolor=#ffffff><div align=center>家庭住址:</div></td> <td height=25 bgcolor=#ffffff>?<input type=text name=address class=inputcss size=25></td> </tr> <tr> <td height=25 colspan=2 bgcolor=#ffffff><div align=center><input type=submit name=submit value=注册 class=buttoncss>??<input type=reset value=重写 class=buttoncss></div></td> </tr> </form> </table></td> </tr> </table> <table width=600 height=80 border=0 align=center cellpadding=0 cellspacing=0> <tr> <td><div align=center><br /> 版权所有?吉林省科技有限公司! 未经授权禁止复制或建立镜像!<br /> copyright ??, all rights reserved! <br /> <br /> 建议您在大于1024*768的分辨率下使用 </div></td> </tr> </table> <?php if($_post['submit']!=){ $dbms='mysql'; //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数 $host='localhost'; //数据库主机名 $dbname='db_database15'; //使用的数据库 $user='root'; //数据库连接用户名 $pass='root'; //对应的密码 $dsn=$dbms:host=$host;dbname=$dbname; try { $pdo = new pdo($dsn, $user, $pass); //初始化一个pdo对象,就是创建了数据库连接对象$pdo $pdo->query(set names utf8); //设置数据库编码格式 $pdo->setattribute(pdo::attr_errmode,pdo::errmode_exception); $nc=$_post['nc']; $pwd=md5($_post['pwd']); $email=$_post['email']; $address=$_post['address']; $query=call pro_reg('$nc','$pwd','$email','$address'); $result=$pdo->prepare($query); if($result->execute()){ echo 数据添加成功!; }else{ echo 数据添加失败!; } } catch (pdoexception $e) { echo 'pdo exception caught.'; echo 'error with the database:<br/>'; echo 'sql query: '.$query; echo '<pre>'; echo error: . $e->getmessage(). <br/>; echo code: . $e->getcode(). <br/>; echo file: . $e->getfile(). <br/>; echo line: . $e->getline(). <br/>; echo trace: . $e->gettraceasstring(). <br/>; echo '</pre>'; } } ?> </body> </html> 二 运行结果
数据添加成功!


域名状态正常但是打开经常会出现这个页面
云服务器备案促销活动
关于推广宝的问题-虚拟主机/数据库问题
注册shop域名多少钱 shop域名有没有交易
考虑到网页设计和页面布局 应该怎么做网页
whois 查询子域名,信息收集总结
无极云节点服务器多少钱一台
买了域名怎么卖出去,有什么方法吗?