Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-21-2007, 03:08 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default [RESOLVED] SQL Statement and the "?" character...

Hi,

I'm trying to run the folowing query, without success. Evertime the "?" in the query is replaced (quoted) by the "'" character and a get a wrong record value in database :

PHP Code:
$sql "UPDATE table SET col = 'Are you fine?' WHERE 1";
$db -> query$sql ); 
Col contains : Are you fine '

Any idea ???

Last edited by flyingbono : 07-25-2007 at 08:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-22-2007, 12:25 AM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 117
Default

you do notice that your using single quotes that aren't escaped?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-22-2007, 10:04 AM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Quote:
Originally Posted by SpotSec View Post
you do notice that your using single quotes that aren't escaped?
No, I say that I dont found any option to configure the PDO:MySQL -> prepare( $sql ) to DO NOT PARSE my query.

Anyway, the PDO library parse the query and interprets the quotation mark character as a bind parameter. Also, its not everytime the case, you may have database contents containing the "?" character !

Try to execute the folowing code :


PHP Code:
$params = array(
    
'host'           => '127.0.0.1',
    
'username'   => 'webuser',
    
'password'   => 'xxxxxxxx',
    
'dbname'     => 'test');
$db Zend_Db::factory('Pdo_Mysql'$params);

$db -> query("UPDATE table SET col = 'Are you fine ?' WHERE 1"); 

How to do to have the correct string (Are you fine ?) in database ? The quotation mark is systematically interpreted and replaced with a single quote !

Thanks in advance for your help. I hope my english is no so poor !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-25-2007, 07:57 AM
Junior Member
 
Join Date: Jul 2007
Posts: 1
Default

That's becuase you should be escaping your values. e.g.
$db->quoteInto('UPDATE table SET col = ? WHERE 1', 'Are you fine ?'); or
$db->query('UPDATE table SET col = '.$db->quote('Are you fine ?').' WHERE 1');
This prevents sql injection attacks, also ensures that any special chars are escaped for use with the database you are currently using, plus allows the sql produced to work in different db servers (e.g. you currrent sql wouldn't work in postgresql)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-25-2007, 08:39 AM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default [RESOLVED] SQL Statement and the "?" character...

Thanks for your help, letssurf.
You're right, next time, I will read the manual with more attention !

So many works to make applications secured...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:00 PM.