Reply to Re: Apostrophe - when used it mucks with my odbc

Your name:

Reply:


Posted by Michael Fesser on 05/13/07 12:21

..oO(Johnny BeGood)

>Thanks for the reply, can you give me some guidance on
>
>> 2) use prepared statements
>>
>> The second is the preferred, but whether it's available or not depends
>> on the used DB backend and the interface.
>
>I have used
>
>$stmt = odbc_prepare($odbc, "INSERT INTO Tasks (TaskType, Details)
>VALUES('$tasktype','$taskdetails');" );

Maybe I should have said "parameterized statement". The purpose of such
statements is to use parameters/placeholders in the query string, which
are replaced with the current values _after_ the statement was prepared.
Your code should look like this (just splitted a bit for legibility):

// query string with 2 placeholders
$query = 'INSERT INTO Tasks (TaskType, Details) VALUES (?, ?)';

// prepare the statement
$stmt = odbc_prepare($odbc, $query);

// pass all parameters in an array and execute the statement
if (!odbc_execute($stmt, array($tasktype, $taskdetails))) {
...
}

HTH
Micha

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация