这是我的代码:
include 'conn.php';
$conn = new Connection();
$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ?';
$stmt = $conn->mysqli->prepare($query);
$stmt->bind_param('sss', $_POST['EmailID'], $_POST['SLA'], $_POST['Password']);
$stmt->execute();
$result = $stmt->get_result();
Run Code Online (Sandbox Code Playgroud)
我在最后一行得到错误:调用未定义的方法mysqli_stmt :: get_result()
这是conn.php的代码:
define('SERVER', 'localhost');
define('USER', 'root');
define('PASS', 'xxxx');
define('DB', 'xxxx');
class Connection{
/**
* @var Resource
*/
var $mysqli = null;
function __construct(){
try{
if(!$this->mysqli){
$this->mysqli = new MySQLi(SERVER, USER, PASS, DB);
if(!$this->mysqli)
throw new Exception('Could not create connection using …Run Code Online (Sandbox Code Playgroud) 我希望将预准备语句的完整结果作为数组(键/值对)得到,以便稍后在str_replace()函数中使用它.
我的表有三列,索引和字段"x1"和"x2".我成功使用了以下内容:
$db = new mysqli("servername", "username", "pw", "dbname");
if($ps1 = $db->prepare("SELECT x1, x2 FROM my_table")) {
$ps1->execute();
$ps1->bind_result($search, $replace);
$result = array();
while ($ps1->fetch()) {
$result[$search] = $replace;
}
$ps1->close();
}
Run Code Online (Sandbox Code Playgroud)
但是,我认为必须有一个更简单的方法,没有while循环,得到完整的结果,而不是逐个单行添加.
我查看了其他问题,我想出了以下内容,但它不起作用("警告:mysqli_fetch_assoc()期望参数1为mysqli_result"):
if($ps1 = $db->prepare("SELECT x1, x2 FROM my_table")) {
$ps1->execute();
$result = mysqli_fetch_assoc($ps1);
return $result;
$ps1->close();
}
Run Code Online (Sandbox Code Playgroud)
我也试过$result = mysqli_fetch_all($ps1);没有成功(获得"调用未定义的函数mysqli_fetch_all()").
顺便说一下,我使用的是PHP 5.6.
关于MYSQLND的评论中的一些答案和讨论之后的补充:
phpinfo()在其mysqlnd部分中显示以下信息:
加载的插件:mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
My following php MYSQLi is not working, PHP version 5.9
$query = $conn->prepare("SELECT * FROM users WHERE token= ? LIMIT 1");
$query->bind_param('s',$cvalue);
$query->execute();
$result = $query->get_result();
$row = $result->fetch_assoc();
Run Code Online (Sandbox Code Playgroud)
It's giving me the following error:
Fatal error: Call to undefined method mysqli_stmt::get_result()
Where is the error? How can I fix it? Thanks