如何使用mysqli_stmt进行2个查询 [英] how to make 2 queries with mysqli_stmt

查看:110
本文介绍了如何使用mysqli_stmt进行2个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用mysqli_stmt进行2个查询?
如果我用一个查询是否可行,但用两个查询则给出此错误:
致命错误:在非对象内部调用成员函数execute()."

How I can make 2 queries with mysqli_stmt?
if I make it with one query if it works, but with two gives me this error:
"Fatal error: Call to a member function execute() on a non-object in."

<?
$oConni=new mysqli('localhost', 'user', 'password', 'database');

$cQuery = "SELECT email, firstname, profile_image FROM usersg";
$stmt = $oConni->prepare($cQuery);
$stmt->execute();
$stmt->bind_result($email, $name, $imagen);

$cQuery2 = "SELECT oauth_uid, oauth_token, username, imagen FROM users";
$resul = $oConni->prepare($cQuery2);
$resul->execute();
$resul->bind_result($id, $fich, $nameTwi, $imagenTwi);

echo "<table border='1'>";
while ($stmt->fetch()) {
echo "<tr>
<td>" . $email. "</td>
<td>" . $name. "</td>
<td><img src='".$imagen."' width=40px height=40px></td>
</tr>";
}
echo "</table><p>";
echo "<table border='1'>";
while ($resul->fetch()) {
echo "<tr>
<td>" . $id. "</td>
<td>" . $fich. "</td>
<td>" . $nameTwi. "</td>
<td><img src='".$imagenTwi."' width=40px height=40px></td>
</tr>";
}
echo "</table>";
?>

推荐答案

尝试一下,肯定可以使用!

thry it, surely it will work !

//First Query
$cQuery = "SELECT email, firstname, profile_image FROM usersg";
$stmt = $oConni->prepare($cQuery);
$stmt->execute();
$stmt->bind_result($email, $nombre, $imagen);
echo "<table border='1'>";
 while ($stmt->fetch()) {
echo "<tr>
<td>" . $email. "</td>
<td>" . $nombre. "</td>
<td><img src='".$imagen."' width=50px height=50px></td>
</tr>";
}
echo "</table>";

//Second Query
$cQuery2 = "SELECT oauth_uid, oauth_token, username, imagen FROM users";
$resul = $oConni->prepare($cQuery2);
$resul->execute();
$resul->bind_result($id, $fichero, $nombreTwitter, $imagenTwitter);
echo "<table border='1'>";
while ($resul->fetch()) {
echo "<tr>
<td>" . $id. "</td>
<td>" . $fichero. "</td>
<td>" . $nombreTwitter. "</td>
<td><img src='".$imagenTwitter."' width=50px height=50px></td>
</tr>";
}
echo "</table>";

这篇关于如何使用mysqli_stmt进行2个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆