The
Recently used a PHP database to access the latest technology POD, not packaged, and the code is written very little. I'll post my code below.
Code part:
<?php $DSN = "Mysql:host=localhost;dbname=mysqldatabasedemo"; $db = new pdo ($dsn, ' root ', ' 123456@# ', Array (pdo::mysql_attr_init_command => )
SET names ' GBK '));
$someInParameter 1= ' hellow ';
$stmt = $db->prepare ("Call outputprocudure (: AddName, @outASD)");
$stmt->bindparam (': AddName ', $someInParameter 1); if ($stmt->execute ()) { $rs = $db->
Query (' select @outASD ')->fetchall ();
$dataArray = $rs [0]; echo ("<script type= ' Text/javascript ' > alert" + $dataArray [
0]+ "');</script>"); &NBSP;&NBSP;&NBSP} else { echo ("<script type
= ' Text/javascript ' > alert (' Insert failed ');</script> "); }?>
MySQL Stored procedures:
Php_pdo A stored procedure that calls MySQL with return parameters
DROP PROCEDURE IF EXISTS pro_test;
CREATE PROCEDURE Pro_test (in Val VARCHAR (m), out RTN int)
begin
Declare err int d Efault 0;
-If an exception occurs, it is automatically processed and ROLLBACK
declare exit handler for SqlException ROLLBACK;
--Start the transaction start
transaction;
insert into test_user values (NULL,1, ' ah is a junior '); - - set err = @ @IDENTITY; -- = Gets the id; set of the last insert ERR&NBSP;=LAST_INSERT_ID (); -- gets the last inserted id insert into test_user values ( Null,val,err); -- Run no exception, COMMIT transaction commit; -- set return value is 1 set rtn=1; end;
$name = ' Chengdu city ';
$stmt = $db->prepare ("Call Pro_test (?, @sp_result);");
$stmt->bindparam (1, $name);
$stmt->execute ();
$outputArray = $db->query ("select @sp_result")->fetch (PDO::FETCH_ASSOC);
<span style= "font-family:arial, Helvetica, Sans-serif;" > </span><span style= "font-family:arial, Helvetica, Sans-serif;" >print_r ($outputArray ["@sp_result"]);</span>