473,412 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

MySQL to PostGres conversion

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
6 5071
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
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
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rob Young | last post by:
Postgres to Mysql I've administrated a few Postgres database servers in the past, but have just started working with mysql, as I've volunteered to admin the mysql server run by my school's comp...
8
by: wlcna | last post by:
mysql v4.0.16: I had been using mysql with innodb and thought that was fine, until i used it for something requiring a few - perhaps slightly involved - joins, and have now seen the performance...
1
by: Canneloni | last post by:
Is there a conversion utility that will take a SQL server database and port it to mySql ( or postGres sql ) ? -- W '04 <:> Open
29
by: smorrey | last post by:
I've been thinking on this long and hard, and I can't seem to come up with an answer on it. Why is it almost always assumed the MySQL will be the server for nearly any PHP app? Why is it...
74
by: John Wells | last post by:
Yes, I know you've seen the above subject before, so please be gentle with the flamethrowers. I'm preparing to enter a discussion with management at my company regarding going forward as either...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
67
by: Bob Powell | last post by:
To whom it may concern: I find the recent articles in various trade publications a little disturbing due to the lack of PostgrSQL mention. I continue to see articles about how IBM may be...
2
by: | last post by:
Perhaps posted it on wrong forums initially as I got only one response (which was helpful but I was looking for more). Please help if you can! =============================================== ...
12
by: howa | last post by:
any side effect for PHP? what do you think?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.