MySQLi
PHP Manual

mysqli::real_query

mysqli_real_query

(PHP 5, PHP 7)

mysqli::real_query -- mysqli_real_query执行一个mysql查询

说明

面向对象风格

bool mysqli::real_query ( string $query )

过程化风格

bool mysqli_real_query ( mysqli $link , string $query )

执行一个单条数据库查询, 其结果可以使用mysqli_store_result()mysqli_use_result()检索或存储.

为了确定给定的查询是否真的返回一个结果集, 可以查看mysqli_field_count().

参数

link

仅以过程化样式:由mysqli_connect()mysqli_init() 返回的链接标识。

query

查询字符串

查询中的数据可以进行属性转义.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

User Contributed Notes

Tinker 26-Oct-2016 07:18
Straightforward function - simply connect to the database and execute a query, similar to this function bellow.

<?php

function check_password($username, $password) {
// Create connection
$db = new mysqli('localhost','database_user','database_pass','database_name');

// Check for errors
if($db->connect_errno){
echo
$db->connect_error;
}

// Execute query
$result = $db->real_query("Select * From users Where username='$username' And password='$password'");

// Always check for errors
if($db->connect_errno){
echo
$db->connect_error;
}

return
$result == true;
}
?>

Very easy.

Replace database_user, database_pass and database_name with the proper names, and the text inside real_query with your actual query.

Don't forget the quotes on either side (except for numbers, there you can omit them) otherwise it won't work. Hope that helps someone.

MySQLi
PHP Manual