Jump to content

SQL search with names like O'


ThunderAI

Recommended Posts

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

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?

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.