这里有些错误,但我无法找到它。 Plz帮助。
我有一个问题:为什么我们最终会关闭连接?这是必要的吗?
$conn = new mysqli($dbConfig['DB_HOST'], $dbConfig['DB_USER'], $dbConfig['DB_PASSWORD'], $dbConfig['DB_NAME']);
if ($conn->connect_errno) {
$errstr = printf("connection has been failed: %s", $conn->connect_error);
echo $errstr;
exit();
}
printf("you are connected to the <b><i>%s</i></b> database successfully.<br>", $dbConfig['DB_NAME']);
$result = $conn->prepare("select * from customers");
if (!$result)
printf('errno: %d, error: %s', $result->errno, $result->error);
$b = $result -> execute();
if (!$b)
echo "execute dosn't work";
$rows = $result->fetch_array(1);
printf("Name is: %s\n <br>",$rows['name']);
代码已更新!
答案 0 :(得分:0)
目前的问题是您需要获得结果http://php.net/manual/en/mysqli-stmt.get-result.php。
所以代码的结尾应该是:
$b = $result->execute();
if (!$b)
echo "execute dosn't work";
$result2 = $result->get_result();
$rows = $result2->fetch_array();