query help

query help

am 17.11.2010 14:51:35 von Vinay Kannan

--0016363b80e4b8115904953ff83a
Content-Type: text/plain; charset=ISO-8859-1

Hello PHP Gurus,

I need your help on an insert query.

I wanted to know if there is way to insert an array of values into a DB. An
eg would explain this better :

If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies = 5 columns

I was thinking of having a single function which will perform the insert on
any insert which happens on the entire website.

Eg : This function can be called with 2 parameters, the first parameter the
table name, and the second parameter is an array of values which will be
inserted into the table.
eg : Users has these columns [1]ID [2] Name [3]Location
so the function call would be something like *
insert_into_tbale(users,array[user_values])*
**
Does this make sense ? Is this a good method to follow ?

Thanks in advance !

Vinay Kannan.

--0016363b80e4b8115904953ff83a--

Re: query help

am 17.11.2010 15:06:34 von Artur Ejsmont

well .... i guess you could do that. but it gets complicated after a
while and there will be a lot of work and probably after a while you
will get into some problems. You have to handle escaping, special
types etc. Then what about performance? how to query the data ...
using similar approach or is it just for inserts? there is a bit of
work to make it really usable i guess.

I am not saying its wrong though, I have seen this approach twice ...
in general its possible.

Maybe better choice would be to try to use some orm ? there are plenty
of frameworks out there .... the only problem is the learning curve
may be steep.

What others think?

art

On 17 November 2010 13:51, Vinay Kannan wrote:
> Hello PHP Gurus,
>
> I need your help on an insert query.
>
> I wanted to know if there is way to insert an array of values into a DB. =
An
> eg would explain this better :
>
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies =3D 5 colum=
ns
>
> I was thinking of having a single function which will perform the insert =
on
> any =A0insert which happens on the entire website.
>
> Eg : This function can be called with 2 parameters, the first parameter t=
he
> table name, and the second parameter is an array of values which will be
> inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location
> so the function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
>
> Thanks in advance !
>
> Vinay Kannan.
>



--=20
Visit me at:
http://artur.ejsmont.org/blog/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: query help

am 17.11.2010 15:08:14 von Phpster

On Wed, Nov 17, 2010 at 8:51 AM, Vinay Kannan wrote:
> Hello PHP Gurus,
>
> I need your help on an insert query.
>
> I wanted to know if there is way to insert an array of values into a DB. =
An
> eg would explain this better :
>
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies =3D 5 colum=
ns
>
> I was thinking of having a single function which will perform the insert =
on
> any =A0insert which happens on the entire website.
>
> Eg : This function can be called with 2 parameters, the first parameter t=
he
> table name, and the second parameter is an array of values which will be
> inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location
> so the function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
>
> Thanks in advance !
>
> Vinay Kannan.
>

codeigniter works this way. But they have a lot of extra functionality
to keep the data safe for inserts. Check it out.

--=20

Bastien

Cat, the other other white meat

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: query help

am 17.11.2010 15:10:42 von Max

From: "Vinay Kannan"
To: "PHP DB" , "php mysql" groups.com>
Sent: Wednesday, November 17, 2010 2:51:35 PM GMT +01:00 Amsterdam / Berlin=
/ Bern / Rome / Stockholm / Vienna
Subject: [PHP-DB] query help

Hello PHP Gurus,

I need your help on an insert query.

I wanted to know if there is way to insert an array of values into a DB. An
eg would explain this better :

If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies =3D 5 columns

I was thinking of having a single function which will perform the insert on
any insert which happens on the entire website.

Eg : This function can be called with 2 parameters, the first parameter the
table name, and the second parameter is an array of values which will be
inserted into the table.
eg : Users has these columns [1]ID [2] Name [3]Location
so the function call would be something like *
insert_into_tbale(users,array[user_values])*
**
Does this make sense ? Is this a good method to follow ?

Thanks in advance !

Vinay Kannan.




Hi Vinay,

You may want to try codeigniter.

More info here.

http://codeigniter.com/user_guide/database/active_record.htm l#insert


with kind regards,

Max.
------------------------------------------------
Max Kimambo
Franz-Stenzer-Straße, 51
12679, Berlin.
T: +493057706550 (new number)
M: +4917649520175
------------------------------------------------

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: query help

am 17.11.2010 15:29:52 von Niel Archer

> Hello PHP Gurus,
>
> I need your help on an insert query.
>
> I wanted to know if there is way to insert an array of values into a DB. An
> eg would explain this better :
>
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies = 5 columns
>
> I was thinking of having a single function which will perform the insert on
> any insert which happens on the entire website.
>
> Eg : This function can be called with 2 parameters, the first parameter the
> table name, and the second parameter is an array of values which will be
> inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location
> so the function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
>
> Thanks in advance !
>
> Vinay Kannan.

You don't give any info about the database engine, but assuming you're
using MySQL take a look at
http://dev.mysql.com/doc/refman/5.0/en/insert.html
Specifically you can use your idea to build an INSERT/VALUE version of
the syntax

INSERT INTO table (col1, col2, .colN.) VALUES (col1Value1, col2value1,
colNvalue1), (col1Value2, col2value2, colNvalue2), ...


--
Niel Archer
niel.archer (at) blueyonder.co.uk


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: query help

am 17.11.2010 15:43:13 von Constantin Brinzoi

Hey,

You can also try PEAR module MDB2 to insert an array into a table. The
function is: "executeMultiple". This works for other SQL queries too.

Check this link please:
http://pear.php.net/manual/en/package.database.mdb2.intro-ex ecute.php

Cheers,


-----Original Message-----
From: Artur Ejsmont [mailto:ejsmont.artur@gmail.com]=20
Sent: 17 noiembrie 2010 16:07
To: Vinay Kannan
Cc: PHP DB; php mysql
Subject: Re: [PHP-DB] query help

well .... i guess you could do that. but it gets complicated after a =
while
and there will be a lot of work and probably after a while you will get =
into
some problems. You have to handle escaping, special types etc. Then what
about performance? how to query the data ...
using similar approach or is it just for inserts? there is a bit of work =
to
make it really usable i guess.

I am not saying its wrong though, I have seen this approach twice ...
in general its possible.

Maybe better choice would be to try to use some orm ? there are plenty =
of
frameworks out there .... the only problem is the learning curve may be
steep.

What others think?

art

On 17 November 2010 13:51, Vinay Kannan wrote:
> Hello PHP Gurus,
>
> I need your help on an insert query.
>
> I wanted to know if there is way to insert an array of values into a=20
> DB. An eg would explain this better :
>
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies =3D 5=20
> columns
>
> I was thinking of having a single function which will perform the=20
> insert on any =A0insert which happens on the entire website.
>
> Eg : This function can be called with 2 parameters, the first=20
> parameter the table name, and the second parameter is an array of=20
> values which will be inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location so the=20
> function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
>
> Thanks in advance !
>
> Vinay Kannan.
>



--
Visit me at:
http://artur.ejsmont.org/blog/

--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: query help

am 17.11.2010 16:27:37 von Ashay Chaudhary

The most performant methods are to use well parameterized stored procedure =
or a prepared parameterized statement.

: Ashay

-----Original Message-----
From: Niel Archer [mailto:not@chance.now]=20
Sent: Wednesday, November 17, 2010 6:30 AM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] query help

> Hello PHP Gurus,
>=20
> I need your help on an insert query.
>=20
> I wanted to know if there is way to insert an array of values into a=20
> DB. An eg would explain this better :
>=20
> If I have 2 tables in a DB, 1) users has 3 columns 2) hobbies =3D 5=20
> columns
>=20
> I was thinking of having a single function which will perform the=20
> insert on any insert which happens on the entire website.
>=20
> Eg : This function can be called with 2 parameters, the first=20
> parameter the table name, and the second parameter is an array of=20
> values which will be inserted into the table.
> eg : Users has these columns [1]ID [2] Name [3]Location so the=20
> function call would be something like *
> insert_into_tbale(users,array[user_values])*
> **
> Does this make sense ? Is this a good method to follow ?
>=20
> Thanks in advance !
>=20
> Vinay Kannan.

You don't give any info about the database engine, but assuming you're usin=
g MySQL take a look at http://dev.mysql.com/doc/refman/5.0/en/insert.html
Specifically you can use your idea to build an INSERT/VALUE version of the =
syntax

INSERT INTO table (col1, col2, .colN.) VALUES (col1Value1, col2value1, col=
Nvalue1), (col1Value2, col2value2, colNvalue2), ...


--
Niel Archer
niel.archer (at) blueyonder.co.uk


--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http=
://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php