By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

MySQL to PostGres conversion

P: n/a
Hi,
I'm porting some php code from mysql to postgres but I canąt find
something equivalent to mysql_select_db(). I use this function to switch
from a DB on machine 1 to a db on machine 2. Is there something similar for
pg ? I'm using php 4.2.2 on a linux box

thanks

thl

Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Th3L0rD wrote:
Hi,
I'm porting some php code from mysql to postgres but I canąt find
something equivalent to mysql_select_db(). I use this function to switch
from a DB on machine 1 to a db on machine 2. Is there something similarfor
pg ? I'm using php 4.2.2 on a linux box

thanks

thl


The answer lies in examining the [xxx]_connect() functions from mysql
and pg.
You will see that the datbase name is required as part of the pg connect
string. It is not required for mysql because you choose which database
at runtime. Postgres does not allow you to change which database you are
using at runtime for the given **connection resource**.

There is also no Postgres command I am aware of that you can execute to
change databases
http://www.postgresql.org/docs/curre...-commands.html

In your previous mysql based code, on what basis do you choose to switch
databases?
Jul 17 '05 #2

P: n/a
Th3L0rD <th*****@nospam.katamail.com> wrote in message news:<Xn**********************************@63.223. 5.254>...
Hi,
I'm porting some php code from mysql to postgres


Why not try http://mp2p.mikekohn.net/ ?

---
"Dying is an art, like everything else"---Sylvia Plath
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

P: n/a
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) writes:
Th3L0rD <th*****@nospam.katamail.com> wrote in message news:<Xn**********************************@63.223. 5.254>...
Hi,
I'm porting some php code from mysql to postgres


Why not try http://mp2p.mikekohn.net/ ?


Or use dbx, avoid using database-specific features, and use a subset
of SQL that's likely to work everywhere. Done correctly, porting
code from one DBMS to another can involve nothing more than changing
the arguments to dbx_connect().

http://www.php.net/manual/en/ref.dbx.php

With dbx you might lose functionality that the database-specific
APIs provide, but if you've ever had to work with multiple DBMSs
or if you've had to port a lot of code from one DBMS to another,
then you might appreciate having a common API.

If dbx is too lacking, then you could write your own module to
provide the functionality you want while hiding the database-specific
details from the application. To port from one DBMS to another,
you'd just change or add a little code in the module instead of
having to change code throughout the application.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #4

P: n/a
mf***@fuhr.org (Michael Fuhr) wrote in message news:<3f**********@omega.dimensional.com>...
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) writes:
Th3L0rD <th*****@nospam.katamail.com> wrote in message news:<Xn**********************************@63.223. 5.254>...
Hi,
I'm porting some php code from mysql to postgres


Why not try http://mp2p.mikekohn.net/ ?


Or use dbx, avoid using database-specific features, and use a subset
of SQL that's likely to work everywhere. Done correctly, porting
code from one DBMS to another can involve nothing more than changing
the arguments to dbx_connect().


So, it's not a wrapper and so I couldn't understand the use of dbx.
If you want to move to another DB, you need to change the whole code
with some search and replace...

My knowledge is limited to native MySQL and PEAR. But, I hate PEAR
because of it's messy. Most often I would use native codes; sometimes
depending upon the project I would go for my own wrapper DB class.

I would like to know the real use of dbx. It seems that you've used
dbx successfully... that's why I've decided to ask you the __real__
benefit of dbx.

TIA

---
"Dying is an art, like everything else"---Sylvia Plath
Email: rrjanbiah-at-Y!com
Jul 17 '05 #5

P: n/a
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) writes:
mf***@fuhr.org (Michael Fuhr) wrote in message news:<3f**********@omega.dimensional.com>...

Or use dbx, avoid using database-specific features, and use a subset
of SQL that's likely to work everywhere. Done correctly, porting
code from one DBMS to another can involve nothing more than changing
the arguments to dbx_connect().
So, it's not a wrapper and so I couldn't understand the use of dbx.
If you want to move to another DB, you need to change the whole code
with some search and replace...


If the application is already written using a database-specific
API, then yes, you have to make global substitutions when porting
to a new database.
I would like to know the real use of dbx. It seems that you've used
dbx successfully... that's why I've decided to ask you the __real__
benefit of dbx.


The benefit of using dbx or any other database abstraction layer
is that you change almost nothing when porting an application to
use a different DBMS: ideally you'd change only one line, the line
that connects to the database. The rest of the application doesn't
know or care whether the database is MySQL, PostgreSQL, Oracle,
Sybase, or whatever. This makes the application more portable and
easier to maintain.

The disadvantage of database abstraction layers is that you can
lose access to features that are by their nature database-specific.
The code might also be less efficient due to the overhead imposed
by the abstraction layer.

Whether the advantages of using a database abstraction layer outweigh
the disadvantages depends on the environment and your priorities.
If the code might have to use different DBMSs, and if the cost of
modifying the code and then testing the changes is expensive, then
using an abstraction layer might be preferable. On the other hand,
if the application is likely to run only in an environment that's
already heavily committed to a particular DBMS, then you might
prefer to use that DBMS's API for efficiency and to gain full access
to its features.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #6

P: n/a
> I'm porting some php code from mysql to postgres but I canąt find
something equivalent to mysql_select_db(). I use this function to
switch from a DB on machine 1 to a db on machine 2. Is there something
similar for pg ? I'm using php 4.2.2 on a linux box

thanks to all for the replies. I simply modified the function that selects
wich DB to use to work properly with PG (I should have read better the
manual ^__^)

thanks again

thl

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.