Enclosing values in single quotes

Поиск
Список
Период
Сортировка
Искать

Enclosing values in single quotes

От:
Ma Siva Kumar <siva@leatherlink.net>
Дата:

I am trying to write a function which takes in an associative array (from a 
user submitted form for example), converts the keys to a column array and 
values to a value array. These arrays together with the name of the database 
table are fed into another function, which generates the query string (insert 
into $table ($colmn) values ($value)).

As a short cut,  I am enclosing all the values (numeric as well as strings) 
in single quotes when generating the arrays.  In my trials so far, 
everything is fine. What will be the issues in enclosing numeric values in 
single quotes?

(I am learning this as a hobby and I do not have any formal training in 
programming).

Any advice please.

Siva


-- 
Ma Siva Kumar
BSG LeatherLink,
No. 9, Trump Castle,
AI/92-A, 9th Main Road,
Anna Nagar, Chennai, 
Tamil Nadu, India - 600040

Email: siva@leatherlink.net
Website: http://www.leatherlink.net/

Re: Enclosing values in single quotes

От:
Martijn van Oosterhout <kleptog@svana.org>
Дата:
On Tue, Jun 18, 2002 at 12:10:58PM +0530, Ma Siva Kumar wrote:
> 
> I am trying to write a function which takes in an associative array (from a 
> user submitted form for example), converts the keys to a column array and 
> values to a value array. These arrays together with the name of the database 
> table are fed into another function, which generates the query string (insert 
> into $table ($colmn) values ($value)).
> 
> As a short cut,  I am enclosing all the values (numeric as well as strings) 
> in single quotes when generating the arrays.  In my trials so far, 
> everything is fine. What will be the issues in enclosing numeric values in 
> single quotes?

Absolutly none. In fact, it will work better than if you attempt to leave
them off, since without quote, they'll all be interpreted as int4. With
quotes, they'll all be interpreted by the appropriate input function for
each type.

Don't forget to escape the ' and \ characters.
-- 
Martijn van Oosterhout      http://svana.org/kleptog/
> There are 10 kinds of people in the world, those that can do binary
> arithmetic and those that can't.
FAQ