PHP - MySQL query with '

software development



I have a script which already running well at other server, after I change to dreamhost hosting with PHP5, the script can not running well.

The problem is appear when I try to query like this :

$query = "SELECT * FROM data WHERE title LIKE ‘$input’ ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

The result will be error with this message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in…

This problem is because I use at it’s. If I change with non ’ string, than the result is ok.

How to solve this problem?
Thank you in advance.


Did you try to resolve the problem by “escaping” the apostrophe? Try this:


…and let me know how that works out :wink:



Does the PHP work if you rename the file .php4?

I think you need ‘addslashes’ in to escape the apostrophe. Also you might (or might not) need ‘stripslashes’ in when reading the data back out. Or use mysql_escape_string() .

See this link.
Also might be worth checking it in the PHP manual page here



Yes, it work with this one :
$query = "SELECT * FROM data WHERE title LIKE ‘$input’ ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
Thank you very much for the answer.

Just curious, why this is happen with dreamhost server while this problem doesn’t happen at my other server?

Thank you in advance.


It was probably PHP4 on your old server and is now PHP5.
The 2 versions are running so you can test under PHP4 still.
It may have something to do with magic quotes being on or off as well.



I got the point now, thank you for your fast reply.

Btw, if I already choose to use PHP5 with a domain, can I change only for php version without delete and re-create the domain at dreamhost panel?

Thank you in advance.


I do not believe you can drop back other than by deleting the domain and starting over. I suppose something might be possible by using an addhandler type in .htaccess but I think the best route would be to go with PHP5.
The two versions are running at the moment but who knows what will happen in a few months.



Ok, nice reply for help my problem. I’m happy with this community and also the dreamhost.

Thank you very-very much.