ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a PHP script that is monitoring a filename and then searches my MySQL database for info on the file. It works unless there is/are ' or - in the filename, and the search fails. I'm assuming that MySQL uses those symbols to modify the search. Is there a way to tell MySQL to use the entire string as the search? Or do I need to rename my files?
PHP Code:
mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM `musicmetadata` WHERE `filename` LIKE '%$string%'"; $result=mysql_query($query);
$string carries the file name obviously.
example of file names:
Code:
01 - artist - song title
artist song title
artist_song_title
etc
I'm not sure what I'm doing wrong, but I tried both addslashes() and mysql_real_escape_string() and it doesn't seem to be changing the string. I echo out the variable after the line and before the search, but there are no slashes. What could I be doing wrong?
function remover($string, $sep1, $sep2) { $string = substr($string, 0, strpos($string,$sep2)); //Finds end position of filename $string = substr(strstr($string, $sep1), 14); //Finds beginning of filename $string = trim($string); //Trims blank space(s) at the beginning and end of string $string = addslashes ($string); #echo get_magic_quotes_gpc(); #echo "($string)"; $username="mythtv"; $password="mythtv"; $database="mythconverg"; #$string = mysql_real_escape_string($string); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM `musicmetadata` WHERE `filename` LIKE '%$string%'"; # mysql_real_escape_string($string)); $result=mysql_query($query);
I echoed out the data after the addslashes() and mysql_real_escape_string() and It doesn't appear to be doing anything. Here is an example output that just happened:
Code:
(Billy Joel - Don`t Ask Me Why)(Billy Joel - Don`t Ask Me Why)
Ok, I think I fixed it. Addslashes doesn't work but I found a little function that appeared that I could use. It seems to be working so far. Thanks for your help!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.