我在您的代码中更改了几处,请查看。
如果您正在使用mysqli
该类,那么您的类 instatiation 之后的任何内容都应该类似于:
$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$con->exampleClassFunction()
使用对象运算符->
。
要获取num_rows
您的对象运算符,将在查询变量之后,如下所示:
$search_res = $con->mysqli_query($con, $search_sql);
$match = $search_res->mysqli_num_rows($search_res);
我还在您的查询中为所有适用的列名添加了反引号:
SELECT `hash`, `active` FROM members WHERE `hash`='".$verification."' AND `active`='0'
这是您的代码示例:
//include("php/functions.php");
$DB_NAME = 'DATABASE_NAME';
$DB_HOST = 'DATABASE_HOST';
$DB_USER = 'DATABASE_USER';
$DB_PASS = 'DATABASE_PASSWORD';
$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
// Added a connection error check before continuing
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if(isset($_GET['verification']) && !empty($_GET['verification'])){
$hash = $con->mysqli_real_escape_string($con, $_GET['verification']);
// Use back ticks on query column names,
// use single quotes for comparative operations
$search_sql = "SELECT `hash`, `active` FROM members WHERE `hash` = '".$verification."' AND `active` = '0'";
$search_res = $con->mysqli_query($con, $search_sql);
$match = $search_res->mysqli_num_rows($search_res);
}