- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的数据库中,我有一些存储过程。
我想调用其中一个,根据我从这个过程中得到的结果,我将确定天气是否调用第二个。
正如您在 isUserValid()
方法中所见,我使用了 $result->free_results()
但在调用其他过程时我仍然得到:Commands out of sync;你现在不能运行这个命令
这是我对数据库函数的调用:
/**
* Run a new query on the db.
* this will open an close the connection to the db
* @param $query string the query to run
* @param $verifyAccessToken boolean true if user validation is needed before query is executed, false otherwise
* @return bool|mysqli_result the result of the query if any or true or false in a non query
* @throws Exception on connection and query errors
*/
private function queryDb($query,$verifyAccessToken)
{
// if ($this->test)
// echo $query . "<br>";
//create a new mysqli connection
$mysqli = new mysqli($this->DB_HOST, $this->DB_USER, $this->DB_PASS, $this->DB_NAME);
//set the charset for the connection
if (!$mysqli->set_charset("utf8"))
{
$mysqli->close();
throw new Exception ("Error setting UTF 8 DB connection");
}
//check if the connection was ok
if (mysqli_connect_errno())
{
$mysqli->close();
throw new Exception("Error connecting DB");
}
//if verification is needed - verify access token
if ($verifyAccessToken && !$this->isUserValid($mysqli))
{
$mysqli->close();
throw new Exception(ACCESS_TOKEN_INCORRECT);
}
//get results
$result = $mysqli->query($query);
//check if there were now error in query. if so - throw an exception
if (!$result)
{
$mysqlError = $mysqli->error . __LINE__;
//close the connection
$mysqli->close();
throw new Exception ("mySQL Error: " . $mysqlError);
}
//fetch the results into an array
$rows = $result->fetch_all(MYSQLI_BOTH);
//close the connection
$result->close();
$result->free();
$mysqli->close();
//return the results if any
return $rows;
}
/**
* Check if user is valid
* @param $mysqli mysqli connection to db
* @return true if user is valid, false otherwise
*/
function isUserValid($mysqli)
{
//Check if there is a saved access token. if not - throw an exception
if (is_null($this->user) || $this->user->getPicoAccessToken() == null)
throw new Exception(ACCESS_TOKEN_INCORRECT);
//get user details
$facebookId = $this->user->getFacebookId();
$picoAccessToken = $this->user->getPicoAccessToken();
//create verification query
$verificationQuery = "Call isUserValid('$facebookId','$picoAccessToken')";
//execute query
$result = $mysqli->query($verificationQuery);
//if query had error - throw exception
if (!$result)
{
$mysqlError = $mysqli->error . __LINE__;
//close the connection
$mysqli->close();
throw new Exception ("mySQL Error: " . $mysqlError);
}
$rows = $result->fetch_all(MYSQLI_ASSOC);
$rows = $rows[0];
$result->free_result();
//return user valid status
return isset($rows["isUserValid"]) && $rows["isUserValid"] == 1;
}
最佳答案
每个存储过程至少返回两个结果
你必须使用 mysqli_more_results()
/mysqli_next_result()
来清理它们。
如果您的过程只返回一个结果,或者您只想要第一个结果以外的任何其他结果,您可以使用以下代码片段清理结果队列:
while($mysqli->more_results())
{
$mysqli->next_result();
if($res = $mysqli->store_result())
{
$res->free();
}
}
关于PHP mysqli 命令不同步;你现在不能运行这个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19077779/
这个问题已经有答案了: php, mysql - Too many connections to database error (6 个回答) 已关闭 8 年前。 伙计们,我的 opencart 网站
这是我想要的,但不能让它与新的 MySQLi 一起工作,只是因为我的主机没有所有新的 php 等... 但是一定有某种解决方案,或者这就是 MYSQLI 能做的? 请不要谈论 PDO,因为即使是丑陋的
这个问题在这里已经有了答案: Is there a way to see a prepared query as it will be executed on the database? [dupli
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\
如何在扩展类中实现 mysqli? 我正在上传图像并将其存储在 MySQL 数据库中,但出现此错误: Notice: Undefined variable: mysqli in ...ecc/ecc/
我终于切换到 mysqli 了。 但是我发现了显着的性能差异。 我有一个脚本,可以进行大约 25.000 个查询。该脚本使用 mysqli 和 mysqlnd 作为驱动程序需要 15 秒10 秒使用
这个问题已经有答案了: Why can't I run two mysqli queries? The second one fails [duplicate] (2 个回答) 已关闭 4 年前。 我
这个问题已经有答案了: mysqli::query(): Couldn't fetch mysqli (4 个答案) 已关闭 6 年前。 这是我当前的代码: query("SELECT * FROM
这个问题在这里已经有了答案: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must
我正在尝试连接到我的数据库,但当我使用 127.0.0.1 而不是本地主机时出现错误。 Warning: mysqli::mysqli(): (HY000/2002): A connection at
使用 WHM 更新 mysql 后我的网站面临这个问题。 Warning: mysqli::mysqli(): Headers and client library minor version mis
我试图通过 MySQLi 将简单数据插入到我的 MySQL 表中,但是它拒绝插入,并且没有报告任何错误消息。 我想强调的是,当直接输入 PhpMyAdmin 时,此查询功能正常(当然,替换了变量) r
我正在使用用户断言函数,例如: debug_assert ( gettype($ob)=='object', "Not an object " .print_r($ob
我有一个每天只有大约 100 人访问的站点,但是当我以用户身份登录时收到此错误消息: Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1203):
我创建了一个 foreach 循环来将数据添加到 MySQL 数据库,但在将第一行添加到数据库后,我收到错误“mysqli::query(): Couldn't fetch mysqli”。 PHP
我正在使用 mysqli 实现一些基本的 getter 函数,并且正在考虑一种在错误检查中变得懒惰但仍然正确的方法。 所以我写了这种类型的代码段 if(!mysqli_stmt_bind_param(
我已经阅读了在线 php 手册,但我仍然不确定这两个函数的工作方式:mysqli::commit 和 mysqli::rollback。 我要做的第一件事是: $mysqli->autocommit(
这个问题在这里已经有了答案: What is the difference between single-quoted and double-quoted strings in PHP? (7 个答
我是一名优秀的程序员,十分优秀!