PHP Implementation PDO Operation mysql Stored Procedure Sample

  • 2021-11-24 01:09:46
  • OfStack

This article illustrates the PHP implementation PDO operation mysql stored procedure. Share it for your reference, as follows:

1 code

sql statement:

create procedure pro_reg (in nc varchar(80), in pwd varchar(80), in email varchar(80),in address varchar(50))
insert into tb_reg (name, pwd ,email ,address) values (nc, pwd, email, address);

index. php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> User registration </title>
<link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" >
<script language="javascript">
 function chkinput(form){
     alert(" Please enter a user nickname !");;
     alert(" Please enter your registration password !");;
     alert(" Please enter E-mail Address !");;
     alert(" Please enter your home address !");;
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
  <td><img src="images/banner.gif" width="500" height="65" /></td>
<table width="500" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <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)">
    <td height="25" colspan="2" bgcolor="#B5D3FF"><div align="center"> User registration </div></td>
    <td width="150" height="25" bgcolor="#FFFFFF"><div align="center"> User nickname: </div></td>
    <td width="347" bgcolor="#FFFFFF">&nbsp;<input type="text" name="nc" class="inputcss" size="25"></td>
    <td height="25" bgcolor="#FFFFFF"><div align="center"> Registration password: </div></td>
    <td height="25" bgcolor="#FFFFFF">&nbsp;<input type="password" name="pwd" class="inputcss" size="25"></td>
    <td height="25" bgcolor="#FFFFFF"><div align="center">E-mail : </div></td>
    <td height="25" bgcolor="#FFFFFF">&nbsp;<input type="text" name="email" class="inputcss" size="25"></td>
    <td height="25" bgcolor="#FFFFFF"><div align="center"> Home address: </div></td>
    <td height="25" bgcolor="#FFFFFF">&nbsp;<input type="text" name="address" class="inputcss" size="25"></td>
    <td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center"><input type="submit" name="submit" value=" Registration " class="buttoncss">&nbsp;&nbsp;<input type="reset" value=" Rewrite " class="buttoncss"></div></td>
<table width="600" height="80" border="0" align="center" cellpadding="0" cellspacing="0">
  <td><div align="center"><br />
     Copyright reserved &nbsp; Jilin Province ** Technology co., ltd !  Unauthorized prohibition of copying or mirroring !<br />
   Copyright &copy;&nbsp;, All Rights Reserved! <br />
   <br />
    It is recommended that you set the 1024*768 Use at the resolution of  </div></td>
     $dbms='mysql'; // Database type  , For developers to use different databases, just change this and don't have to remember so many functions 
    $host='localhost'; // Database Hostname 
    $dbName='db_database15'; // Database used 
    $user='root'; // Database connection user name 
    $pass='root'; // Corresponding password 
    try {
      $pdo = new PDO($dsn, $user, $pass); // Initialization 1 A PDO Object, that is, the database connection object is created $pdo
        $pdo->query("set names utf8"); // Setting database encoding format 
        $query="call pro_reg('$nc','$pwd','$email','$address')";
            echo " Data added successfully! ";
            echo " Data addition failed! ";
    } 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>';

2 Running results

Data added successfully!

For more readers interested in PHP related contents, please check the topics on this site: "Summary of PHP Database Operation Skills Based on pdo", "Summary of php+Oracle Database Programming Skills", "Encyclopedia of PHP+MongoDB Database Operation Skills", "Introduction to php Object-Oriented Programming", "Introduction to php String (string) Usage", "Introduction to php+mysql Database Operation Skills" and "Summary of php Common Database Operation Skills"

I hope this article is helpful to everyone's PHP programming.

Related articles: