[英]Example php code for connecting and getting a sql stored proceedure
任何人都可以给出用于连接和获取sql存储过程的Example php代码
what do you prefer to use? 您更喜欢使用什么? Here is an example taken from php.net:
这是取自php.net的示例:
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "CALL get_items(1, @param1, @param2); ";
/* execute multi query */
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
remember, that you have to free the resultset, if you do not, you will get an error while executing a next query. 请记住,您必须释放结果集,否则,在执行下一个查询时会出现错误。
Before I know something about mysqli, I apply mysqli to handle sp's. 在我对mysqli有所了解之前,我将mysqli应用于处理sp。 Just take a look at the follwing example:
只需看下面的示例:
$rs = mysql_query("CALL get_items(1, @param1, @param2); ");
$rs = mysql_query("SELECT @param1, @param2" );
while($row = mysql_fetch_assoc($rs))
{
print_r($row);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.