note 99945 deleted from function.mysql-real-escape-string by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 20:40:34 +0000 |
| Subject: | note 99945 deleted from function.mysql-real-escape-string by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203682@lists.php.net to get a copy of this message | ||
Note Submitter: anonymous at host dot com
----
You can also use the escape function in a manner as shown in the snapshot out of my own browsertools
class:
<?php
//
// MySQL Database connection
//
public function mysqlConnect($host, $user, $password, $database) {
$this->mysql = mysql_connect($host, $user, $password);
if (!$this->mysql) die(mysql_error());
mysql_select_db($database, $this->mysql);
}
//
// MySQL Query
// usage:
// $query such as "SELECT * FROM users WHERE nick = '%s' AND pass =
'%s'"
// where %s are the placeholders for the parameters
// call:
// $__->mysqlQuery( $query, arg0, arg1, arg2, ... )
// description:
// The parameters given to the function are escaped through mysql_real_escape_string(),
// merged with the query and then given to the mysql_query function.
// returns:
// Array of lines returned by the MySQL Database
//
public function mysqlQuery($query) {
$numParams = func_num_args();
$params = func_get_args();
if ($numParams > 1) {
for ($i = 1; $i < $numParams; $i++){
$params[$i] = mysql_real_escape_string($params[$i]);
}
$query = call_user_func_array('sprintf', $params);
}
$this->result = mysql_query($query, $this->mysql);
if (!$this->result) die(mysql_error());
$ret = array();
while ($row = mysql_fetch_assoc($this->result)) {
$ret[] = $row;
}
mysql_free_result($this->result);
return $ret;
}
?>