[PHP-DB] supporting multiple databases...

2005-01-30 Thread Paul Chvostek
Hiya.

I'm writing an application which needs to make SQL queries, and I'd like
to give it support for multiple database servers, starting with MySQL
and PostgreSQL.  I see that other folks have done this with a variety of
methods, and I can't see a clear winner.

Option 1 - Drop in a set of db-related functions as part of the install
procedure.  I.e. a file db_func.php is copied from db_func.php-pg or
db_func.php-my as part of the install procedure.  The functions
contained will return equivalent results.  This has the advantage of
leaving the installed application more streamlined, but it requires
better coordination between functions and things that call them; your
total number of db functions is multiplied by the number of databases
supported.

Option 2 - Select function behaviour based on a config variable.  That
is, the same database functions will run, but there can be if() or
switch() statements to control how the db is dealt with.  This keeps the
function list tighter, but it seems to make for less elegant and
probably less maintainable code.

Option 3 - Write relatively generic database functions, but control the
format of SELECTs and even the db connect functions called from config
variables.  This seems elegant on the surface, but make for highly
obtuse code.

Is there a preferred method of handling this issue, or does everybody
just roll their own?

-- 
  Paul Chvostek [EMAIL PROTECTED]
  it.canadahttp://www.it.ca/

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



Re: [PHP-DB] supporting multiple databases...

2005-01-30 Thread Josip Dzolonga
On Sun, 2005-01-30 at 14:42 -0500, Paul Chvostek wrote:
 I'm writing an application which needs to make SQL queries, and I'd like
 to give it support for multiple database servers, starting with MySQL
 and PostgreSQL.

Take a look here http://www.php.net/dbx and here
http://pear.php.net/package/DB . 
-- 
Josip Dzolonga,
dzolonga at mt dot net dot mk

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



Re: [PHP-DB] supporting multiple databases...

2005-01-30 Thread Bastien Koert
also look a this class...adodb.php
a good article on it is here
http://www.databasejournal.com/features/php/article.php/10898_651_1
bastien
From: Josip Dzolonga [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: Re: [PHP-DB] supporting multiple databases...
Date: Sun, 30 Jan 2005 20:49:48 +0100
On Sun, 2005-01-30 at 14:42 -0500, Paul Chvostek wrote:
 I'm writing an application which needs to make SQL queries, and I'd like
 to give it support for multiple database servers, starting with MySQL
 and PostgreSQL.
Take a look here http://www.php.net/dbx and here
http://pear.php.net/package/DB .
--
Josip Dzolonga,
dzolonga at mt dot net dot mk
--
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


[PHP-DB] SQL prob

2005-01-30 Thread Bobo Wieland
Anyone that can help me with this one? I want this SQL-statement to 
retrive only distinct values from the original table column named (not 
the AS stuff)

(
SELECT * , namn_2 AS sec_namn, namn_1 AS one
FROM sortiment
WHERE namn_1 LIKE 'H%'
)
UNION (
SELECT * , UPPER( namn_2 ) AS sec_namn, namn_2 AS one
FROM sortiment
WHERE namn_2 LIKE 'H%'
AND SUBSTRING( namn_2, 1, 1 ) LIKE BINARY 'H'
)
ORDER BY one
LIMIT 0 , 10
this will return, for example, the following row twice where (in the 
original table)
namn_1 = Humulus lupulus
namn_2 =  Humle

the two rows are identical except for the sec_namn and one created 
by the query. They are set to:
sec_namn  one
HUMLEHumle
HumleHumulus lupulus


_bobo wieland _ [EMAIL PROTECTED] _
winamp  Not playing anything right now...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] SQL prob

2005-01-30 Thread Micah Stevens

use DISTINCT?

On Sunday 30 January 2005 12:51 pm, Bobo Wieland wrote:
 Anyone that can help me with this one? I want this SQL-statement to
 retrive only distinct values from the original table column named (not
 the AS stuff)

 (
 SELECT * , namn_2 AS sec_namn, namn_1 AS one
 FROM sortiment
 WHERE namn_1 LIKE 'H%'
 )
 UNION (

 SELECT * , UPPER( namn_2 ) AS sec_namn, namn_2 AS one
 FROM sortiment
 WHERE namn_2 LIKE 'H%'
 AND SUBSTRING( namn_2, 1, 1 ) LIKE BINARY 'H'
 )
 ORDER BY one
 LIMIT 0 , 10

 this will return, for example, the following row twice where (in the
 original table)
 namn_1 = Humulus lupulus
 namn_2 =  Humle

 the two rows are identical except for the sec_namn and one created
 by the query. They are set to:
 sec_namn  one
 HUMLEHumle
 HumleHumulus lupulus




 _bobo wieland _ [EMAIL PROTECTED] _
 winamp  Not playing anything right now...

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



RE: [PHP-DB] timestamp

2005-01-30 Thread Balwant Singh
thanks 
I tried strtotime also but getting 1970-01-01 not 2005-01-28.  my
problem is that the date is given to me in string format i.e.Fri Jan 28
19:53:09 2005.  Any other help will be appreciated.

with best wishes
balwant


On Sat, 2005-01-29 at 22:45, Bastien Koert wrote:
 try
 
 $date = date(Y-m-d,strtotime($timestamp));
 
 Best thing to use if you want to do calcs on date/time data is to use the 
 unix time stamp...translates the timestamp into seconds since 
 01-01-1970...Much simpler to use in sql queries
 
 Bastien
 
 From: Balwant Singh [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: php-db@lists.php.net
 Subject: [PHP-DB] timestamp
 Date: 29 Jan 2005 19:47:35 +0530
 
 i am facing a problem
 
 i have timestamp in string format -- Fri Jan 28 19:53:09 2005 now i
 want to get the date from it.  is it possible? pls. help. on using
 strftime(%D,$timestamp) it is giving 01/01/70.  May pls. help me.
 
 Also pls. let me know whether calculation can be done in mysql on this
 string timestamp. pls. inform.
 
 
 
 with best wishes
 balwant
 
 --
 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] timestamp

2005-01-30 Thread Dianne Mead
what about something like this?


$strdate = Fri Jan 28 19:53:09 2005;   // place your date string here
$newstr = substr_replace($strdate, '', 11, -5); // removes the time from
your date string, bringing it inline with format required by strtotime()
$tmstmp = strtotime($newstr);
$date = date(Y-m-d,$tmstmp);

Cheers,
Dianne

- Original Message - 
From: Balwant Singh [EMAIL PROTECTED]
To: Bastien Koert [EMAIL PROTECTED]
Cc: php-db@lists.php.net
Sent: Sunday, January 30, 2005 11:32 PM
Subject: RE: [PHP-DB] timestamp


 thanks
 I tried strtotime also but getting 1970-01-01 not 2005-01-28.  my
 problem is that the date is given to me in string format i.e.Fri Jan 28
 19:53:09 2005.  Any other help will be appreciated.

 with best wishes
 balwant


 On Sat, 2005-01-29 at 22:45, Bastien Koert wrote:
  try
 
  $date = date(Y-m-d,strtotime($timestamp));
 
  Best thing to use if you want to do calcs on date/time data is to use
the
  unix time stamp...translates the timestamp into seconds since
  01-01-1970...Much simpler to use in sql queries
 
  Bastien
 
  From: Balwant Singh [EMAIL PROTECTED]
  Reply-To: [EMAIL PROTECTED]
  To: php-db@lists.php.net
  Subject: [PHP-DB] timestamp
  Date: 29 Jan 2005 19:47:35 +0530
  
  i am facing a problem
  
  i have timestamp in string format -- Fri Jan 28 19:53:09 2005 now i
  want to get the date from it.  is it possible? pls. help. on using
  strftime(%D,$timestamp) it is giving 01/01/70.  May pls. help me.
  
  Also pls. let me know whether calculation can be done in mysql on this
  string timestamp. pls. inform.
  
  
  
  with best wishes
  balwant
  
  --
  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


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