我想用一个名为$params
的数组创建一个准备语句。当我运行我的脚本,我得到以下错误:准备好的语句中的数组不工作
Fatal error: Call to a member function bind_param() on a non-object in /home/morea/directory-new.php on line 110
线110 $stmt->bind_param('i', $place_holders);
$params = array(5, 6, 7, 9, 10, 11, 12, 3, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 4, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42);
/* Create a string for the parameter placeholders filled to the number of params */
$mysqli = new MySQLi("localhost", "erpa", "48p", "le3");
$mysqli->set_charset('utf8');
$place_holders = implode(',', array_fill(0, count($params), '?'));
$sth = ("SELECT u.url, COUNT(u.url) AS total, u.SiteTypeID, p.SiteType FROM sites AS u LEFT JOIN sitetypes AS p USING (SiteTypeID) WHERE SiteTypeID=($place_holders)");
$stmt = $mysqli->prepare($sth);
$stmt->bind_param('i', $place_holders);
$stmt->execute($params);
$query5 = mysqli_query($dbc, $sth);
while($row2 = mysqli_fetch_array($sql3, MYSQLI_ASSOC) && $row4 = mysqli_fetch_array($query5, MYSQLI_ASSOC)){
if ($row4['SiteType'] == 'selected'){
$list .= $row4['total'];
$list .= '<option value="'.$row4['SiteTypeID'].'"';
$list .= "selected='selected'>";
$list .= $row4['SiteType'];
$list .= "</option>";
}
}
为什么你有'mysqli_query($ dbc,$ sth);'在那里? –
使用fetch_array与我的sql语句 – user3286022
这不正确的使用'mysqli_query'。 –