Solved

PHP and Mysql !!

Posted on 1998-10-12
5
338 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

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now