MySQL to PostGres conversion

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default 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

    Th3L0rD Guest

  2. Similar Questions and Discussions

    1. Java: MySQL DATETIME conversion errors?
      I do the following in my java application: Statement s = myConnection.createStatement(); ResultSet rs = s.executeQuery("SELECT startTime FROM...
    2. mysql charaters conversion
      Dears, Is there any simple way to convert characters from national characters to 'flat' ascii characters without using cast or convert...
    3. postgres vs Mysql
      I need to decide on which database system to use for our company. What is the popular opinion on PostGres vs. MySql? Thanks, Santosh
    4. Help needed for TimeStamp conversion between MySQL and PHP
      On Sun, 06 Jul 2003 19:17:58 GMT, "Steven" <xueming@comcast.net> wrote: ...
    5. Statement Conversion Access -> mySQL
      SQL = "DELETE FROM table WHERE ID IN (1, 9, 15, 20)" The above statement is for deleting records in access using checkboxes on a form (deletes...
  3. #2

    Default Re: MySQL to PostGres conversion

    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
    [url]http://www.postgresql.org/docs/current/interactive/sql-commands.html[/url]

    In your previous mysql based code, on what basis do you choose to switch
    databases?


    Terence Guest

  4. #3

    Default Re: MySQL to PostGres conversion

    Th3L0rD <th3l0rd@nospam.katamail.com> wrote in message news:<Xns943D8A5B6B0BAth3l0rdnospamkatamai@63.223. 5.254>...
    > Hi,
    > I'm porting some php code from mysql to postgres
    Why not try [url]http://mp2p.mikekohn.net/[/url] ?

    ---
    "Dying is an art, like everything else"---Sylvia Plath
    Email: rrjanbiah-at-Y!com
    R. Rajesh Jeba Anbiah Guest

  5. #4

    Default Re: MySQL to PostGres conversion

    [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh Jeba Anbiah) writes:
    > Th3L0rD <th3l0rd@nospam.katamail.com> wrote in message news:<Xns943D8A5B6B0BAth3l0rdnospamkatamai@63.223. 5.254>...
    > > Hi,
    > > I'm porting some php code from mysql to postgres
    >
    > Why not try [url]http://mp2p.mikekohn.net/[/url] ?
    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().

    [url]http://www.php.net/manual/en/ref.dbx.php[/url]

    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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  6. #5

    Default Re: MySQL to PostGres conversion

    [email]mfuhr@fuhr.org[/email] (Michael Fuhr) wrote in message news:<3fc2f398$1_4@omega.dimensional.com>...
    > [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh Jeba Anbiah) writes:
    >
    > > Th3L0rD <th3l0rd@nospam.katamail.com> wrote in message news:<Xns943D8A5B6B0BAth3l0rdnospamkatamai@63.223. 5.254>...
    > > > Hi,
    > > > I'm porting some php code from mysql to postgres
    > >
    > > Why not try [url]http://mp2p.mikekohn.net/[/url] ?
    >
    > 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
    R. Rajesh Jeba Anbiah Guest

  7. #6

    Default Re: MySQL to PostGres conversion

    [email]ng4rrjanbiah@rediffmail.com[/email] (R. Rajesh Jeba Anbiah) writes:
    > [email]mfuhr@fuhr.org[/email] (Michael Fuhr) wrote in message news:<3fc2f398$1_4@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
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  8. #7

    Default Re: MySQL to PostGres conversion

    > 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

    Th3L0rD Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139