473,654 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Porting Code to Postgresql

Hi all,

Not sure if this is a question for a php list or this one, but I'll give it
a shot and
if I am wrong, please do not crucify me. :-)

There is a php based sourceforge project called mailwatch.
(http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent
Mailscanner security product into a mysql database. Now, I am not a php
programmer,
and I am barely a Postgres DBA, but I would really like to port the code to
Postgresql.
I have my trust Postgresql Book which covers the API for Postgresql and the
PHP statements
used for Postgresql seem almost identical to those used for Mysql. I
understand that there are
some slight differences in the data types supported by Mysql and
Postgresql, however are the differences
between the two Databases and API's that great to make task impossible for
an unexperienced person
such as myself? We currently use Postgresql in conjunction with sendmail to
store our access, mailertable
and other db's, so it would be very convenient for us to achieve this.
Best Regards,

Errol U. Neal
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
11 2918
On Wed, 15 Oct 2003 10:16:29 -0400 Errol Neal <sy*******@enht ech.com> wrote:
There is a php based sourceforge project called mailwatch.
(http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent
Mailscanner security product into a mysql database. Now, I am not a php
programmer,
and I am barely a Postgres DBA, but I would really like to port the code to
Postgresql.
I have my trust Postgresql Book which covers the API for Postgresql .... and the PHP statements
used for Postgresql seem almost identical to those used for Mysql. I
understand that there are
some slight differences in the data types supported by Mysql and
Postgresql, however are the differences
between the two Databases and API's that great to make task impossible for
an unexperienced person
such as myself?


it shouldn't be too awful as long as you're willing to learn.

watch for case folding issues. i ultimately ended up always making my table
names and column names all lower because of the way that php behaves with
case. if you have mixed case stuff, then ultimately you will end up
spending a lot of time chasing annoying, stupid bugs because php doesn't
require variables to be initialized, it just creates them, so you could end
up referencing $row->ColumnName and getting null because php put it in
$row->columnname.

when iterating over a result set, be aware that in at least some versions
of the php->postgresql interface,

while( $row = pg_fetch_object ( $result, $row))
{
...
}

will error at the last row instead of returning a false value. you need to do:

$count = pg_numrows( $result);
for( $i = 0; $i < $count; $i++){
$row = pg_fetch_object ( $result, $row);
...
}

if you want it to work.

richard
--
Richard Welty rw****@averillp ark.net
Averill Park Networking 518-573-7592
Java, PHP, PostgreSQL, Unix, Linux, IP Network Engineering, Security
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #2
If the code is hard coded to use the built in mysql function calls, you
can replace them with postgresql calls or add a layer of database
abstraction. Once you dump the schema into postgres and make whatever
datatype etc, changes that need to be made you should be able to test
the application by running it. If it works you can go straight to
performance tuning 8) if not you will have to visit each statement and
resolve the issues one at a time. I recomment turning on query logging
in your postgresql.conf file to make the debugging process easier.

Good Luck - although it may seem daunting the task is probably more
tedious than difficult.

-r

On Wed, 2003-10-15 at 10:16, Errol Neal wrote:
Hi all,

Not sure if this is a question for a php list or this one, but I'll give it
a shot and
if I am wrong, please do not crucify me. :-)

There is a php based sourceforge project called mailwatch.
(http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent
Mailscanner security product into a mysql database. Now, I am not a php
programmer,
and I am barely a Postgres DBA, but I would really like to port the code to
Postgresql.
I have my trust Postgresql Book which covers the API for Postgresql and the
PHP statements
used for Postgresql seem almost identical to those used for Mysql. I
understand that there are
some slight differences in the data types supported by Mysql and
Postgresql, however are the differences
between the two Databases and API's that great to make task impossible for
an unexperienced person
such as myself? We currently use Postgresql in conjunction with sendmail to
store our access, mailertable
and other db's, so it would be very convenient for us to achieve this.
Best Regards,

Errol U. Neal
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

--
Ryan Mahoney <ry**@paymental liance.net>
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #3
$count = pg_numrows( $result);
for( $i = 0; $i < $count; $i++){
$row = pg_fetch_object ( $result, $row);
...
}

if you want it to work.

in case of no rows, maybe do:

$count = pg_numrows( $result);
while ( 0 < $result ){
$result--;
$row = pg_fetch_object ( $result, $row);
...
}

or

$count = pg_numrows( $result);
$offset = $count;
while ( 0 < $offset ){
$offset--;
$row = pg_fetch_object ( $result-$offset, $row);
...
}

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #4
On Wed, 15 Oct 2003 08:43:07 -0700 Dennis Gearon <ge*****@firese rve.net> wrote:
$count = pg_numrows( $result);
for( $i = 0; $i < $count; $i++){
.... in case of no rows, maybe do:

$count = pg_numrows( $result);
while ( 0 < $result ){

....

shouldn't make a difference; in php, the condition on a for() should be at
the top of the loop anyway.

richard
--
Richard Welty rw****@averillp ark.net
Averill Park Networking 518-573-7592
Java, PHP, PostgreSQL, Unix, Linux, IP Network Engineering, Security
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #5
I would guess most likely not. There are a few mysql features that postgres
doesn't have (for example mysql_insert_id ) but there are still ways to do
them in postgers. I doubt it will be very hard.

----- Original Message -----
From: "Errol Neal" <sy*******@enht ech.com>
To: <pg***********@ postgresql.org>
Sent: Wednesday, October 15, 2003 8:16 AM
Subject: [GENERAL] Porting Code to Postgresql

Hi all,

Not sure if this is a question for a php list or this one, but I'll give it a shot and
if I am wrong, please do not crucify me. :-)

There is a php based sourceforge project called mailwatch.
(http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent Mailscanner security product into a mysql database. Now, I am not a php
programmer,
and I am barely a Postgres DBA, but I would really like to port the code to Postgresql.
I have my trust Postgresql Book which covers the API for Postgresql and the PHP statements
used for Postgresql seem almost identical to those used for Mysql. I
understand that there are
some slight differences in the data types supported by Mysql and
Postgresql, however are the differences
between the two Databases and API's that great to make task impossible for
an unexperienced person
such as myself? We currently use Postgresql in conjunction with sendmail to store our access, mailertable
and other db's, so it would be very convenient for us to achieve this.
Best Regards,

Errol U. Neal
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #6
On Wed, 15 Oct 2003, Errol Neal wrote:
Hi all,

Not sure if this is a question for a php list or this one, but I'll give it
a shot and
if I am wrong, please do not crucify me. :-)

There is a php based sourceforge project called mailwatch.
(http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent
Mailscanner security product into a mysql database. Now, I am not a php
programmer,
and I am barely a Postgres DBA, but I would really like to port the code to
Postgresql.
I have my trust Postgresql Book which covers the API for Postgresql and the
PHP statements
used for Postgresql seem almost identical to those used for Mysql. I
understand that there are
some slight differences in the data types supported by Mysql and
Postgresql, however are the differences
between the two Databases and API's that great to make task impossible for
an unexperienced person
such as myself? We currently use Postgresql in conjunction with sendmail to
store our access, mailertable
and other db's, so it would be very convenient for us to achieve this.


The issues you're likely to hit are twofold:

The first is that MySQL silently accepts that which postgresql may reject.
Look for errors on insert when this happens. for example, in postgresql,
you use the SQL keyword DEFAULT when inserting an autoincrement field, or
leave it out of your list of inserted fields. In MySQL you insert,
counterintuitiv ely, a NULL to do the same thing.

The second is the lack of a mysql_last_id type function. While you can
get the last OID of an insert in postgresql, this is discouraged, as OIDs
may or may not exist for a given table depending on how it was declared.
Tis better to use the currval() / nextval() functions for such things.

All the rest if pretty straight forward hacking, having converted or
helped to convert a few other MySQL tools to Postgresql recently.
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #7
On Wed, Oct 15, 2003 at 12:44:55PM -0600, scott.marlowe wrote:
All the rest if pretty straight forward hacking, having converted or
helped to convert a few other MySQL tools to Postgresql recently.


Of course, to get maximum performance you should drop the MySQL support
and instead of coding workarounds for missing functionality, use
whatever Postgres gives you (which is much more than what MySQL gives
you).

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Si quieres ser creativo, aprende el arte de perder el tiempo"

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #8
My guess is this will happen natually after using postgres for a short time.
(That's what happened to me.)

----- Original Message -----
From: "Alvaro Herrera" <al******@dcc.u chile.cl>
To: "scott.marl owe" <sc***********@ ihs.com>
Cc: "Errol Neal" <sy*******@enht ech.com>; <pg***********@ postgresql.org>
Sent: Wednesday, October 15, 2003 1:04 PM
Subject: Re: [GENERAL] Porting Code to Postgresql

On Wed, Oct 15, 2003 at 12:44:55PM -0600, scott.marlowe wrote:
All the rest if pretty straight forward hacking, having converted or
helped to convert a few other MySQL tools to Postgresql recently.


Of course, to get maximum performance you should drop the MySQL support
and instead of coding workarounds for missing functionality, use
whatever Postgres gives you (which is much more than what MySQL gives
you).

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Si quieres ser creativo, aprende el arte de perder el tiempo"

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #9
On Wed, 15 Oct 2003, Dennis Gearon wrote:
$count = pg_numrows( $result);
for( $i = 0; $i < $count; $i++){
$row = pg_fetch_object ( $result, $row);
...
}

if you want it to work.

in case of no rows, maybe do:

$count = pg_numrows( $result);
while ( 0 < $result ){
$result--;
$row = pg_fetch_object ( $result, $row);
...
}


But you don't want to decrement $result, it's a result handle, you want to
decrement count:

$count = pg_numrows( $result);
while ( 0 < $count ){
$count--;
$row = pg_fetch_object ( $result, $row);
...
}

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2147
by: Sonny | last post by:
I need to port a library that is written entirely in C to C++. The library is supported on quite a few platforms (windows, Solaris, Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer base that uses it. I need to maintain backwards compatibility such that existing users won't have to do anything to their existing applications other than a re-compile when they upgrade to this new version of the library. I figure that I...
5
2860
by: Ryan Liu | last post by:
Hi All, Now I am porting CC to GCC and I have some problems. Would you mind tell me some document which have some description how to port CC to GCC ?? Thank you very much. Ryan
1
426
by: Errol Neal | last post by:
Hi all, Not sure if this is a question for a php list or this one, but I'll give it a shot and if I am wrong, please do not crucify me. :-) There is a php based sourceforge project called mailwatch. (http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent Mailscanner security product into a mysql database. Now, I am not a php programmer,
4
2367
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light, fast database abstraction layer which conforms to the behavior of the MySQL functions in PHP. This means that a large amount of porting work could be made simple using this porting layer if the application was originally used PHP's native MySQL...
3
2133
by: Rod Early | last post by:
I have the task of converting a SQL Server 2000 database to PostgreSQL. The data itself does not need to be converted, but the structure and stored procedures must be. I expect that converting tables and views will be simple. I expect that converting stored procedures and user-defined functions from T-SQL to PostgreSQL will be more complex. In any case, I am looking for recommendations and counsel regarding my expectations. I have...
1
1704
by: pwbyrne | last post by:
Hi, I'm looking for details, or tools about porting a full Ms Sql Server 2000 database to Postgres on Linux. Is this possible? We have the whole nine yards, stored procedures, triggers, and all. Is there a way to automate this process?
4
1868
by: Ted | last post by:
Understand, I have developed a number of applications using RDBMS, including MySQL, PostgreSQL and MS Access, but this is my first experience with MS SQL. I'd bet my bottom dollar that MS SQL supports what I need, but I just haven't found where it is explained in any detail in the documentation I have. The pages I have found strike me as a little too terse for my needs. In MySQL, I used statements like: PRIMARY KEY (`ic_contact_id`),...
4
1972
by: Ian | last post by:
I would like to hear from others who have considered and/or ported code from traditional C++ to C++/CLI. The class library I am considering porting to C++/CLI was written in traditional C++ with STL and a touch of MFC. It represents the back end to my applications and, among a number of other things, it performs all file I/O and data management operations (i.e. no GUI). Why would I consider porting it to C++/CLI when it works just...
34
4045
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5621
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.