So I am attempting to learn mysqli and do some database querying. I am using the class file that's found here Simple-Mysqli
I want to make sure that I do this right to prevent any mysql injection attempts but I am having a bit of trouble.
Here's my attempt at a query:
$id = '1776425144629';
$query = "SELECT * FROM article WHERE type = 'lnews' AND article_id = " . $id;
$query = $database->escape($query);
$results = $database->get_results( $query );
foreach( $results as $row )
{
echo $row['headline'] .'<br />';
}
When I use the $database->escape() call that's in the class file (shown here)
public function escape( $data )
{
if( !is_array( $data ) )
{
$data = $this->link->real_escape_string( $data );
}
else
{
//Self call function to sanitize array data
$data = array_map( array( $this, 'escape' ), $data );
}
return $data;
}
It errors out on me and shows the following:
Query: SELECT * FROM article WHERE type = \'lnews\' AND article_id = 1776425144629
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'lnews\' AND article_id = 1776425144629' at line 1
So my question is, how can I pass some parameters to the sql statement, still using the escape or filter function to prevent any mysqli injections?