Solved

PHP and Mysql !!

Posted on 1998-10-12
5
336 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Fine
  Magic_quotes was the answer !!


0
 

Accepted Solution

by:
m4io earned 80 total points
Comment Utility
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

7 Experts available now in Live!

Get 1:1 Help Now