I need to search all elements of an array of strings of the database and to return how many values are matched to the existing database entries..
database name = words , table name=collection , word is the coloumn in which array to bi searched
<?php
$array=array('abc','xyz','lmn','pqr');
@ $db=new mysqli('localhost','root','','words');
if(mysqli_connect_errno()) {
echo 'Error:Could not connect to the database';
} else echo 'connected';
$db->select_db('words');
foreach($array as $s) {
$query="select * from collection where word = '%".$s."%'";
$result=$db->query($query);
}
if($result) echo $db->affected_rows;
$db->close();
?>
addslashes()is not meant for SQL escaping.WHERE word LIKE ? OR word LIKE ? OR ...