错误提示就如标题所示,网上也找了一圈,差不多都是说没有开启php_mysqli模块,我的wampserver环境本身已经开启,但是我还是去重新关闭在开启,结果都是一样,有一点很奇怪,网上一般都是在链接数据库的时候失败,但是我链接数据库没有提示失败,而是在使用mysqli_num_row时候出现错误
下面先上下我在查看phpinfo下mysqli下的开启情况
mysqli
MysqlI Support enabled
Client API library version mysqlnd 5.0.8-dev - 20102224 - $Id: 65fe78e70ce53d27a6cd578597722950e490b0d0 $
Active Persistent Links 0
Inactive Persistent Links 0
Active Links 0
Directive Local Value Master Value
mysqli.allow_local_infile On On
mysqli.allow_persistent On On
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.max_persistent Unlimited Unlimited
mysqli.reconnect Off Off
下面是我的代码部分
<?phprequire ('inc/config.php');$page_title = '注册-CNode博客';include ('inc/header.php');if ($_SERVER['REQUEST_METHOD'] == 'POST') { require (MYSQL); $trimmed = array_map('trim', $_POST); $errors = array(); if ($_POST['code'] != $_SESSION['code']) { $errors[] = '验证码不正确!'; } if(empty($trimmed['username'])) { $errors[] = '用户名不能为空'; } else { if (preg_match ('/^[A-Z \'.-]{5,20}$/i', $trimmed['username'])) { $un = mysqli_real_escape_string ($conn, $trimmed['username']); } else { $errors[] = '您的用户名格式不对'; } } if(empty($trimmed['email'])) { $errors[] = '电子邮件地址不能为空'; } else { if (filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) { $e = mysqli_real_escape_string ($conn, $trimmed['email']); } else { $errors[] = '您的电子邮件地址格式不对'; } } if(!empty($trimmed['password'])) { if (preg_match ('/^\w{4,20}$/', $trimmed['password']) ) { if ($trimmed['password'] == $trimmed['notpassword']) { $p = mysqli_real_escape_string ($conn, $trimmed['password']); } else { $errors[] = '登录密码和确认密码不一致'; } } else { $errors[] = '请输入有效的登录密码'; } } else { $errors[] = '登录密码不能为空'; } if(empty($trimmed['notpassword'])) { $errors[] = '确认密码不能为空'; } if (empty($errors)) { // 确定电子邮件是否被使用 $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($conn, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($conn)); if (mysqli_num_row($r) == 0) { // 如果查询验证电子邮件地址未被使用,则注册用户 $a = md5(uniqid(rand(), true)); // 创建一个激活码(创建一个长度正好为32个字符的字符串) $q = "INSERT INTO users (username, email, password, active, registration_date) VALUES ('$un', '$e', SHA1('$p'), '$a', NOW() )"; $r = mysqli_query ($conn, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($conn)); if (mysqli_affected_rows($conn) == 1) { $body = "感谢您的注册,激活您的帐户,请点击这里:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], '确认注册', $body, 'From: 414412984@qq.com'); echo '<h3>感谢您的注册!一封确认邮件已经发送到您的邮箱。请在该电子邮件中单击链接,以激活您的帐户。</h3>'; exit(); } else { echo '<p class="error">用户注册失败,为此我们表示抱歉,请在注册一次</p>'; } } else { // 查询验证出来的电子邮件地址已经被注册 echo '<p class="error">电子邮件地址已经被注册</p>'; } } else { foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } } mysqli_close($conn);}?><div class="wrap login"> <div class="path"><a href="#">主页</a> > 注册</div> <div class="info"> <form method="post" name="register" action=""> <p> <label for="username">用户名:</label><input type="text" name="username" id="username" class="text" value="<?php if (isset($trimmed['username'])) echo $trimmed['username']; ?>" /> <span>限5~20个字符,可用中文、英文、数字及“_”、“-”组成</span> </p> <p> <label for="email">电子邮件:</label><input type="text" name="email" id="email" class="text" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> <span>请填写您的常用邮箱,它是您激活帐号和找回密码的凭证!</span> </p> <p> <label for="password">登录密码:</label><input type="password" name="password" id="password" class="text" value="<?php if (isset($trimmed['password'])) echo $trimmed['password']; ?>" /> <span>密码由4-20位字母、数字组成</span> </p> <p> <label for="notpassword">确认密码:</label><input type="password" name="notpassword" id="notpassword" class="text" value="<?php if (isset($trimmed['notpassword'])) echo $trimmed['notpassword']; ?>" /> <span>请再次输入密码</span> </p> <p> <label for="yzm">验证码:</label><input type="text" name="code" id="yzm" class="text1" /> <img src="code.php" id="code" /> <span>看不清,请重新点击验证码(注意大小写)</span> </p> <div class="submit"> <input type="submit" name="submit" class="btn-1" value="立即注册" /> </div> </form> </div> </div> <?phpinclude ('inc/footer.php');?>
print_r(get_extension_funcs('mysqli'));
真是和你说的一样,太粗了心,你给的方法很直观,谢谢