Solved

PHP and Mysql !!

Posted on 1998-10-12
5
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

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 video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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