这是我的数据库连接类。如何将连接链接调用到mysqli_real_escape_string()中。我收到一个错误,还有一个参数必须给mysqli函数。我尝试给$ this->链接,但它不接受。
DBclass.php
class Database {
var $server = "localhost"; //database server
var $user = "root"; //database login name
var $pass = ""; //database login password
var $database = "database name"; //database name
#######################
//internal info
var $error = "";
var $errno = 0;
//number of rows affected by SQL query
var $affected_rows = 0;
var $link_id = 0;
var $query_id = 0;
#-#############################################
# desc: constructor
function Database($server, $user, $pass, $database, $pre=''){
$this->server=$server;
$this->user=$user;
$this->pass=$pass;
$this->database=$database;
$this->pre=$pre;
$this->link_id = mysqli_connect("$server", "$user", "$pass", "$database") or die("Could not connect : " . mysqli_error());
mysqli_select_db($this->link_id,"$database") or die("Could not select database <b>$database</b>");
}#-#constructor()
And here is my registration page. I need to know how to give connection parameter to mysqli_real_escape_string (). Its showing error as mysqli_real_escape_string() needs one more parameter. Plese help out.. Thanks in advance
和registration.php
if(isset($_POST['submit']))
{
extract($_POST);
$employee_id = mysqli_real_escape_string(htmlspecialchars(trim($employee_id)));
$salutation = mysqli_real_escape_string(htmlspecialchars(trim($salutation)));
$middle_name = mysqli_real_escape_string(htmlspecialchars(trim($middle_name)));
$first_name = mysqli_real_escape_string(htmlspecialchars(trim($first_name)));
$last_name = mysqli_real_escape_string(htmlspecialchars(trim($last_name)));
$gender = mysqli_real_escape_string(htmlspecialchars(trim($gender)));
$dob = mysqli_real_escape_string(htmlspecialchars(trim($dob)));
$mobile = mysqli_real_escape_string(htmlspecialchars(trim($mobile)));
答案 0 :(得分:1)
mysqli_real_escape_string()函数需要两个参数; mysqli_connect()函数的值和您已经拥有的变量。 你应该有像
这样的东西$dob = mysqli_real_escape_string($this->link, htmlspecialchars(trim($dob)));
答案 1 :(得分:0)
请使用带有两个参数的函数,一个是您的数据库连接变量,第二个是您必须传递数据。
mysqli_real_escape_string($this->link_id, htmlspecialchars(trim($dob)));