Subject | RE: [firebird-php] Handling quote characters in Firebird/PHP |
---|---|
Author | Nigel Weeks |
Post date | 2006-03-01T22:18:28Z |
> What is the best practice way of handling fields with single quoteI simply do a search and replace for single quotes, and turn them into two
> characters purposely entered into them, and getting this data
> into Firebird?
>
>
single quotes:
Here's a simple snippet of PHP
<?php
if(!$conn =
ibase_connect("server:/path/to/database.fdb","sysdba","masterkey)){
echo "Sorry, could not connect to the database. Aborting for the following
reason:";
echo ibase_errmsg();
} else {
// Connect was successful
// Here, we prepare the variables we're received from the form for
inserting into the DB
// Mainly, replace one single quote (') with two single quotes ('')
$surname = str_replace("'","''",$surname);
$firstname = str_replace("'","''",$firstname);
// Ok. Our surname is now safe to insert, let do it!
$sql = "insert into tbl_contact(int_contact,str_firstname,str_surname)
values (gen_id(gen_tbl_contact,1), '$firstname', '$surname')";
$rec = ibase_query($sql);
} // End of successfull connection
?>