Solved

PHP and Mysql !!

Posted on 1998-10-12
5
344 Views
Last Modified: 2010-03-18
I got a problem with PHP and a HTTP request from a Delphiapplication to a MySql-Database.
PHP seem to excape some letters \'  and \"
here's what I sent with a Post command:
  'select [field] from [table] where [field] like "Aa%"';
it works from the commandprompt on Linux-MySQL.
But PHP escapes the " and % which means that MYSQL doesn't
understand it !!
- Can I pass the string to MySQL from PHP without theese
  escapecodes ??  or is there an other solution ??
0
Comment
Question by:Jeb
  • 3
  • 2
5 Comments
 

Expert Comment

by:m4io
ID: 1587162
MySQL likes commands within single quotes, this could be
the problem. If Delphi should expand "Aa%" into something
like "expanded_string" then single quotes work perfectly.

PHP uses $string instead of string% , but I guess this has
nothing to do with your problem ..

0
 

Author Comment

by:Jeb
ID: 1587163
that didn't answer my question !!

$Strings and String% is not my problem !!
$String is MySQL and "string%" is part of an SQL-quiery.
As you say MySQL should take escaped "  and ' but it doesn't seem to work.

0
 

Expert Comment

by:m4io
ID: 1587164
Quote from the mysql documentation :

SELECT * from banner where banner_group LIKE '%value%';

So string% should work, also when executed from a PHP
script. The actual problem might be somewhere else in your
script. Have you checked the result code when you execute the query ?

On the other hand, if you create a string in PHP like this :

$string = 'this is some text and "this is something else" ';
then the string really contains the double quotes before this
and after else. You might have to build a string using chr(34) codes for double quotes. I had to do this in many ASP scripts before I worked with PHP and also in PHP these codes are sometimes required. Variables within strings which are enclosed in single quotes, are not (!) replaced by their values.

So $string = 'hello $name'; will output hello $name if you print it and not hello <value of $name>.

Also check this value : (From the documentation of PHP)

magic_quotes_gpc boolean
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.


0
 

Author Comment

by:Jeb
ID: 1587165
Fine
  Magic_quotes was the answer !!


0
 

Accepted Solution

by:
m4io earned 80 total points
ID: 1587166
To close the question here is the answer again :

Quote from the mysql documentation :

SELECT * from banner where banner_group LIKE '%value%';

So string% should work, also when executed from a PHP
script. The actual problem might be somewhere else in your
script. Have you checked the result code when you execute the query ?

On the other hand, if you create a string in PHP like this :

$string = 'this is some text and "this is something else" ';
then the string really contains the double quotes before this
and after else. You might have to build a string using chr(34) codes for double quotes. I had to do this in many ASP scripts before I worked with PHP and also in PHP these codes are sometimes required. Variables within strings which are enclosed in single quotes, are not (!) replaced by their values.

So $string = 'hello $name'; will output hello $name if you print it and not hello <value of $name>.

Also check this value : (From the documentation of PHP)

magic_quotes_gpc boolean
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.

0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question