【发布时间】:2012-06-25 16:01:38
【问题描述】:
我正在尝试获取查询中的行数,但它一直给我这个错误
尝试在第 15 行获取非对象的属性。
<?php require_once("./includes/Utilities.php") ;?>
<?php require_once("./includes/db_connection.php");?>
<?php
if(isset($_POST['submit'])){
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$conf_pass = trim($_POST['conf_password']);
$email = trim($_POST['email']);
require_once('./includes/CheckPassword.php');
$check_pwd = new Db_CheckPassword($password);
$check_pwd =$check_pwd->check();
require_once('./includes/CheckUsername.php');
$sql = "SELECT * FROM accounts WHERE username = {$username}";
$result = $conn->query($sql);
$numRows = $result->num_rows;
}
?>
这是第 15 行
$numRows = $result->num_rows;
为什么会返回错误?
【问题讨论】:
-
当你使用 MySQLi 时,你没有使用准备好的语句!这导致了与旧数据库驱动程序引入的相同类型的 SQL 注入漏洞!
-
mysqli存储过程和执行查询有什么区别?
-
我不是说存储过程,我是说prepared statements
-
抱歉,打错了,所以这就是他们的不同之处?强烈建议使用准备好的语句吗?为什么?
-
extermely建议使用准备好的语句。在批量执行多个查询时,它可以提高性能,并且它还会自动转义您输入的任何变量。