Hi im trying to build a replacement for a standard mysql query to replace it with my custom class which i intend to make with memcache support, the problems im having are due to building my query, since the data is not set im sending my query information in an array. i need to filter the parameters though and build a sprinft query, therefore im using array_map so i can apply a function to each parameter but my problem is that im also using the mysqli class
I tried to do this
array_map($this->mysqli->real_escape_string, $query['parameters']);
but php didnt like that either, i also tried many ideas. i then thought about creating a function then within the function sorting the issue. This then created another problem of how do i send my $this or just $this->mysqli to this function
//ERROR IS HERE !
function _escape($value){
return $this->mysqli->real_escape_string($value);
}
//apply functions to each parameter
$query['parameters'] = array_map("_escape", $query['parameters']);
FULL CODE
<?php
class mysqli_cache{
#Objects
public $mysqli;
private $memcache;
public function __construct(){
//open memcache connection
}
public function __destroy(){
//close memcache
//if mysqli is open close it
}
public function query($query, $cache_time){
if(!is_object($this->mysqli)){
$this->mysqli = new mysqli('localhost', 'root', 'letmein', 'test');
}
//ERROR IS HERE !
function _escape($value){
return $this->mysqli->real_escape_string($value);
}
//apply functions to each parameter
$query['parameters'] = array_map("_escape", $query['parameters']);
foreach($query['parameters'] as $value){//now the parameters are safe add them to the query
array_push($query['sql'], $value);
}
$query = call_user_func_array('sprintf', $query['sql']);
die($query);
}
}
$cache = new mysqli_cache();
$query = array('sql' => array(), 'parameters' => array());
$query['sql'][0] = "SELECT * FROM test WHERE test='%u' LIMIT 1";
$query['parameters'][0] = "1";
$result = $cache->query($query, 60);
?>