ThunderAI Posted August 22, 2008 Share Posted August 22, 2008 Just how do I do that? Here is a typical sql statement: $nsql = '(`fieldname` LIKE CONVERT(_utf8 \'%'.$arr[0].'%\' USING latin1) COLLATE latin1_swedish_ci '; a name like O'Reily would go in the array $arr[0]. If I try to put two ''s in name then the program crashes. What am I missing? Link to comment https://forums.phpfreaks.com/topic/120860-sql-search-with-names-like-o/ Share on other sites More sharing options...
revraz Posted August 22, 2008 Share Posted August 22, 2008 Are you adding slashes when you insert into the DB? Link to comment https://forums.phpfreaks.com/topic/120860-sql-search-with-names-like-o/#findComment-622984 Share on other sites More sharing options...
ThunderAI Posted August 22, 2008 Author Share Posted August 22, 2008 Are you adding slashes when you insert into the DB? The information comes from a CSV file. If I manualy add the slashes into the CSV file it works. I suppose I could do a search of the column see if there is a ' in it and add a \ right before it. What would that code even look like? Link to comment https://forums.phpfreaks.com/topic/120860-sql-search-with-names-like-o/#findComment-622996 Share on other sites More sharing options...
revraz Posted August 22, 2008 Share Posted August 22, 2008 How are you bringing the contents of the CSV file into the DB? You should be able to use addslashes when you insert. Link to comment https://forums.phpfreaks.com/topic/120860-sql-search-with-names-like-o/#findComment-623000 Share on other sites More sharing options...
ThunderAI Posted August 22, 2008 Author Share Posted August 22, 2008 How are you bringing the contents of the CSV file into the DB? You should be able to use addslashes when you insert. It never is brought into a DB, its read into an array and then pared against something already in a DB. The CSV file never is imported. I could add the slahes when I read the data into the array. But how? Here is the code to explode the line of the CSV file into an array $line = trim($fcontents[$i],','); $arr = explode(",",$line); Link to comment https://forums.phpfreaks.com/topic/120860-sql-search-with-names-like-o/#findComment-623002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.