Re: [PHP-DB] query help

2010-11-17 Thread 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 viny...@gmail.com 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 = 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.




-- 
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: [PHP-DB] query help

2010-11-17 Thread Bastien Koert
On Wed, Nov 17, 2010 at 8:51 AM, Vinay Kannan viny...@gmail.com 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 = 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.


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

-- 

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: [PHP-DB] query help

2010-11-17 Thread Max E.K
From: Vinay Kannan viny...@gmail.com
To: PHP DB php-db@lists.php.net, php mysql 
php_mysql_usergr...@yahoogroups.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 = 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.html#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: [PHP-DB] query help

2010-11-17 Thread 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: [PHP-DB] query help

2010-11-17 Thread 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-execute.php

Cheers,


-Original Message-
From: Artur Ejsmont [mailto:ejsmont.ar...@gmail.com] 
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 viny...@gmail.com 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 = 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.




--
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: [PHP-DB] query help

2010-11-17 Thread 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:n...@chance.now] 
Sent: Wednesday, November 17, 2010 6:30 AM
To: php-db@lists.php.net
Subject: Re: [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 = 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



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



RE: [PHP-DB] Query Help...

2003-03-10 Thread George Pitcher
Scott,

'Group' is a reserved word so you can't use it for a column name. try
changing it to 'groups' or soething else that makes sense but is safe.

George

 -Original Message-
 From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]
 Sent: 10 March 2003 5:24 pm
 To: '[EMAIL PROTECTED]'
 Subject: [PHP-DB] Query Help...


   I am having a lot of trouble with a query that works fine from a
 basic SQL command line, but fails in my web script.  Here is the
 portion of
 code including the query:

 mysql_select_db($database, $Prod);
 $query_groups = SELECT name FROM group;
 $groups = mysql_query($query_groups, $Prod) or die(mysql_error());

   Here is the error I am receiving:

   You have an error in your SQL syntax near 'group' at line 1

   I am wondering if for some reason group is trying to be
 interperetted as the GROUP BY MySQL function?  I am running PHP 4.2.3
 against a MySQL DB on an Apache 1.3.27 server.  Thanks in advance for the
 help.

 Scott Nipp
 Phone:  (214) 858-1289
 E-mail:  [EMAIL PROTECTED]
 Web:  http:\\ldsa.sbcld.sbc.com



 --
 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: [PHP-DB] Query Help...

2003-03-10 Thread Rob Bryant
- Original Message -
From: NIPP, SCOTT V (SBCSI) [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 10, 2003 9:23 AM
Subject: [PHP-DB] Query Help...


 I am having a lot of trouble with a query that works fine from a
 basic SQL command line, but fails in my web script.  Here is the
portion of
 code including the query:

 mysql_select_db($database, $Prod);
 $query_groups = SELECT name FROM group;
 $groups = mysql_query($query_groups, $Prod) or die(mysql_error());

 Here is the error I am receiving:

 You have an error in your SQL syntax near 'group' at line 1


Have you tried using backticks in your query? E.g.,

$query_groups = SELECT name FROM `group`;

--
rob


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



RE: [PHP-DB] Query Help...

2003-03-10 Thread NIPP, SCOTT V (SBCSI)
Thanks for all the advice, I thought it might have something to do
with being a reserved word.  I changed the table name from group to grps,
and everything works fine now.

-Original Message-
From: Rob Bryant [mailto:[EMAIL PROTECTED]
Sent: Monday, March 10, 2003 11:39 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Query Help...


- Original Message -
From: NIPP, SCOTT V (SBCSI) [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 10, 2003 9:23 AM
Subject: [PHP-DB] Query Help...


 I am having a lot of trouble with a query that works fine from a
 basic SQL command line, but fails in my web script.  Here is the
portion of
 code including the query:

 mysql_select_db($database, $Prod);
 $query_groups = SELECT name FROM group;
 $groups = mysql_query($query_groups, $Prod) or die(mysql_error());

 Here is the error I am receiving:

 You have an error in your SQL syntax near 'group' at line 1


Have you tried using backticks in your query? E.g.,

$query_groups = SELECT name FROM `group`;

--
rob


-- 
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: [PHP-DB] Query help

2001-11-19 Thread Matt Williams

This doesn't work either.

SELECT count(freerooms.room), WEEK(MAX(booking.date),1),
WEEK(MIN(booking.date),1) as total FROM freerooms LEFT JOIN booking
USING(room);

  All good so far
  now if I run this
 
  SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1)
 FROM freero
  oms f, booking b;
  -+---+-+-+
  | count(f.room) | WEEK(MAX(b.date),1) | WEEK(MIN(b.date),1) |
  +---+-+-+
  | 24817 |  48 |  40 |
  +---+-+-+
 

What I have found is

freerooms.room has 83 rows and booking has 299.
The value returned for count(f.room) is these two figures multiplied.???

Why would it do this?
And how can I get it to return the real value only

Regards

M:


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Query help

2001-11-19 Thread Dobromir Velev

Hi,
I haven't seen the previous posts so I'm not sure want you want to do, but
it looks like that you need to specify a join condition. If freerooms.room
and booking.room are the corresponding fields from your table the query
should look something like this

SELECT count(freerooms.room), WEEK(MAX(booking.date),1),
WEEK(MIN(booking.date),1) as total FROM freerooms LEFT JOIN booking ON
freerooms.room=booking.room
USING(room);

or

SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1)
FROM freerooms f, booking b
WHERE f.room=b.room

Hope this helps
Dobromir Velev

-Original Message-
From: Matt Williams [EMAIL PROTECTED]
To: Andrey Hristov [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED] [EMAIL PROTECTED]
Date: Monday, November 19, 2001 10:26
Subject: RE: [PHP-DB] Query help


This doesn't work either.

SELECT count(freerooms.room), WEEK(MAX(booking.date),1),
WEEK(MIN(booking.date),1) as total FROM freerooms LEFT JOIN booking
USING(room);

  All good so far
  now if I run this

  SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1)
 FROM freero
  oms f, booking b;
  -+---+-+-+
  | count(f.room) | WEEK(MAX(b.date),1) | WEEK(MIN(b.date),1) |
  +---+-+-+
  | 24817 |  48 |  40 |
  +---+-+-+
 

What I have found is

freerooms.room has 83 rows and booking has 299.
The value returned for count(f.room) is these two figures multiplied.???

Why would it do this?
And how can I get it to return the real value only

Regards

M:


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Query help

2001-11-16 Thread Andrey Hristov

SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
oms f, booking b;

will be
SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
oms f LEFT JOIN booking USING(room) b;

room is the field which connects two tables. If it has different name change it in 
USING
Other problems?
Write..

Regards,

Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS

- Original Message - 
From: Matt Williams [EMAIL PROTECTED]
To: Php-Db@Lists. Php. [EMAIL PROTECTED]
Sent: Friday, November 16, 2001 5:20 PM
Subject: [PHP-DB] Query help


 Not really this list but I'm after a quick bit of help.
 If I run this query
 
 select count(room) from freerooms;
 -83
 
 and this
 
 SELECT WEEK(MAX(date),1), WEEK(MIN(date),1)as totalweeks FROM booking;
 -48 40
 
 All good so far
 now if I run this
 
 SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
 oms f, booking b;
 -+---+-+-+
 | count(f.room) | WEEK(MAX(b.date),1) | WEEK(MIN(b.date),1) |
 +---+-+-+
 | 24817 |  48 |  40 |
 +---+-+-+
 
 It seems to be mulitplying out for some reason but I'm stuck as to how/why
 and how to resolve it.
 
 TIA
 
 M:
 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Query help

2001-11-16 Thread Andrey Hristov

Ooops

SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freerooms as f LEFT 
JOIN booking AS b USING(room);

Apolgizes

- Original Message - 
From: Andrey Hristov [EMAIL PROTECTED]
To: Matt Williams [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, November 16, 2001 5:32 PM
Subject: Re: [PHP-DB] Query help


 SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
 oms f, booking b;
 
 will be
 SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
 oms f LEFT JOIN booking USING(room) b;
 
 room is the field which connects two tables. If it has different name change it in 
USING
 Other problems?
 Write..
 
 Regards,
 
 Andrey Hristov
 IcyGEN Corporation
 http://www.icygen.com
 BALANCED SOLUTIONS
 
 - Original Message - 
 From: Matt Williams [EMAIL PROTECTED]
 To: Php-Db@Lists. Php. [EMAIL PROTECTED]
 Sent: Friday, November 16, 2001 5:20 PM
 Subject: [PHP-DB] Query help
 
 
  Not really this list but I'm after a quick bit of help.
  If I run this query
  
  select count(room) from freerooms;
  -83
  
  and this
  
  SELECT WEEK(MAX(date),1), WEEK(MIN(date),1)as totalweeks FROM booking;
  -48 40
  
  All good so far
  now if I run this
  
  SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1) FROM freero
  oms f, booking b;
  -+---+-+-+
  | count(f.room) | WEEK(MAX(b.date),1) | WEEK(MIN(b.date),1) |
  +---+-+-+
  | 24817 |  48 |  40 |
  +---+-+-+
  
  It seems to be mulitplying out for some reason but I'm stuck as to how/why
  and how to resolve it.
  
  TIA
  
  M:
  
  
  -- 
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
  
  
 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]