In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to call mysql stored procedures in php. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
Stored procedures and functions were just introduced by MySql5.0. There is no direct support for this operation in PHP. However, due to the design of Mysql PHP API, we can support calls to stored procedures and functions in mysql php api in previous versions of PHP.
Call stored procedures and functions in php.
one. The method that calls the stored procedure.
A . If the stored procedure has an IN/INOUT parameter, declare a variable and input the parameter to the stored procedure, which is a pair of
A php variable (it may not be necessary, but when there is no php variable, there is no way to dynamically input), a Mysql
Variable.
B . If the stored procedure has an OUT variable, declare a Mysql variable.
The declaration of the mysql variable is special, and you must let the mysql server know that this variable exists, that is, execute a mysql statement.
Enter set @ mysqlvar=$phpvar
C . Use mysql_query () / mysql_db_query () to execute the mysql variable declaration statement.
Mysql_query ("set @ mysqlvar[ = $pbpvar]")
In this way, there is a variable in the mysql server, @ mysqlar. If the IN parameter, then its value can be passed in by phpar.
D . If the stored procedure.
one. Execute the call procedure () statement.
That is, mysql_query ("call proceduer ([var1]..."))
two。 If there is a return value, execute select @ ar and return the execution result.
Mysql_query ("select @ var)"
The next operation is the same as when php executes a normal mysql statement. You can get the results through functions such as mydql_fetch_row ().
If the time function. Just execute select function () directly.
$host= "localhost"
$user= "root"
$password= "11212"
$db= "samp_db"
$dblink=mysql_connect ($host,$user,$password)
Or die ("can't connect to mysql")
Mysql_select_db ($db,$dblink)
Or die ("can't select samp_db")
$res=mysql_query ("set @ a=$password", $dblink)
$res=mysql_query ("call aa (@ a)", $dblink)
$res=mysql_query ("select @ a", $dblink)
$row=mysql_fetch_row ($res)
Echo $row [0]
After reading the above, do you have any further understanding of how to call mysql stored procedures in php? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.