- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一些存储过程,成功后以:
select 1 as outcome;
这样我就知道它成功了。
在 PHP 中我的代码是这样的:
if ($stmt = mysqli_prepare($con, "call storedProc(?)")) {
mysqli_stmt_bind_param($stmt, 'i', $count);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($result);
$outcome = $row['outcome'];
if ($outcome == 1) {
if ($stmt = mysqli_prepare($con, "call secondStoredProc(?)")) {
xxx();
现在的问题是每一次,即使 $outcome
为 1,xxx();
也不会运行。我知道这是因为函数 xxx
不是有效函数,我在控制台中没有收到任何错误。
奇怪的是,它只是下一次运行 mysqli_prepare()
的尝试失败了。请注意,call secondStoredProc(?)
从根本上没有任何错误,如果我在 mysqli_prepare()
之前重新连接,否则它会失败,但它可以正常工作,但是:
mysqli_prepare()
之间重新连接到 MySQL。我找不到任何引用(在文档或任何其他关于 mysqli 的指南中)需要在运行另一个之前正确关闭准备好的语句。除了重新连接之外,我也找不到任何方法来这样做,甚至假设这在任何方面都是问题的本质。
请帮忙。
最佳答案
检查一下...希望这有助于实现您正在尝试做的事情。
一些数据库连接文件在这里
define("HOST", "yo.ur.ip.addr"); // The host you want to connect to.
define("USER", "myfunctionalaccount"); // The database username.
define("PASSWORD", "superdoopersecurepassword!"); // The database password.
define("DATABASE", "thegoods");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ( $mysqli->connect_error ) {
die('Connect Error: ' . $mysqli->connect_error);
}
这里有一些 PHP 函数
function somecoolfunction($someparameter)
if ($stmt = $mysqli->prepare("call storedProc(?)") {
$stmt->bind_param($someparameter);
$stmt->execute();
$stmt->bind_result($outcome);
$stmt->fetch();
if ($stmt->num_rows == 1) {
if ($substmt = $mysqli->prepare("call secondStoredProc(?)") {
$substmt->bind_param($outcome);
$substmt->execute();
$substmt->bind_result($newoutcome);
$substmt->fetch();
xxx();
$mysqli->query(" "); // some other random query
echo $substmt->affected_rows.' rows were updated based on '.$outcome.'.';
} // $substmt closes mysqli connection here
} else {
//$stmt results return 0 or more than 1 result
}
} // $stmt closes mysqli connection here
} // end of function
// You can use this method if you're considering on using w/o the if loops.
$stmt = $mysqli->prepare("call storedProc(?)") //preparing w/o if statement
$stmt->bind_param($someparameter);
$stmt->execute();
$stmt->bind_result($outcome);
$stmt->fetch();
$stmt->close(); //must close since it's not closed conditionally with an if statement.
$stmt = $mysqli->prepare("call secondStoredProc(?)")
$stmt->bind_param($outcome);
$stmt->execute();
$stmt->bind_result($newoutcome);
$stmt->fetch();
$stmt->close();
echo "Stored Proc Outcome: ".$outcome."\nSecond Stored Proc Outcome: ".$newoutcome;
关于php - mysqli_fetch_assoc 会停止下一个 mysqli_prepare 工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32462783/
我有一个插入查询,我一直在整个网站使用它。工作完美,我在这个网页中使用了 came 查询,但已经向查询添加了验证。我现在已经运行了查询,但收到以下错误: Undefined variable: run
我正在尝试使用 call_user_func_array 将参数绑定(bind)到 sql 语句,如 Dynamically Bind Params in Prepared Statements wi
This article PHP 手册的一部分在此处使用 mysqli_prepare(),而在其他所有地方使用 mysqli_stmt_*。 然而,在this article在 PHP 手册中,它使
哪个更快: 1. $name = $sql->real_escape_string($_POST['name']); $age = $sql->real_escape_string($_POST
我有一些存储过程,成功后以: select 1 as outcome; 这样我就知道它成功了。 在 PHP 中我的代码是这样的: if ($stmt = mysqli_prepare($con, "c
我是一名优秀的程序员,十分优秀!