The code below receives a query and may only execute it when the query contains 'INSERT' or 'UPDATE'. But when I feed it 'INSERT INTO test_table (id, test_value) VALUES (1, 'Test')', it raises the 'requires an Update or Insert query'.
What am I missing?
public function setQuery($query)
{
if(strpos($query, 'INSERT') === false && strpos($query, 'UPDATE') === false ) {开发者_如何学编程
trigger_error('Method [' . __FUNCTION__ . '] requires an Update or Insert query [Q: '.$query.']');
exit;
}
$this->_queries++;
mysql_query($query);
$this->_result = mysql_insert_id();
if(!$this->_result) {
trigger_error('Method [' . __FUNCTION__ . '] failed [Q: '.$query.']');
}
return $this->_result;
}
Maybe someone send you 'insert'? Try stripos :)
It works when I try it using the parameter you provided.
(BTW it'll be a bit more robust if you use stripos)
Can't tell you why its not working for you.
C.
精彩评论