我第一次尝试使用 mysqli,我需要沿着我的脚本做一些查询。这是基本流程:
$mysqli = new mysqli("localhost", "root", "", "kiosk");
if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; }
$mysqli->real_query("SELECT * FROM screens WHERE name = '" . $screen_code . "'");
$res = $mysqli->use_result();
$row = $res->fetch_assoc();
print_r(_content($row['wcode']));
die();
function _content($wcode) {
global $mysqli;
$mysqli->real_query("SELECT * FROM content WHERE wcode= '" . $wcode. "' ORDER BY id ASC");
$res = $mysqli->use_result();
}
mysql查询是正确的,已经直接在mysql上测试过,如果在_content中我重新连接到数据库一切正常,但我不想每次想查询时都连接。