473,387 Members | 1,493 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,387 software developers and data experts.

odbc: mysql vs. postgresql


I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')

I'd like to have a single syntax for both databases. Is this possible?
Do I need to modify either database configuration settings? Does each
database (MySQL, PGSQL, MSSQL, Oracle, ...) use its own SQL syntax?

Any advice welcome.
Sep 30 '06 #1
9 2438
Jacques Lebastard wrote:
>
I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')

I'd like to have a single syntax for both databases. Is this possible?
Do I need to modify either database configuration settings? Does each
database (MySQL, PGSQL, MSSQL, Oracle, ...) use its own SQL syntax?

Any advice welcome.
Both MySQL and Postgres support standardized SQL constructs, within the
restrictions of the release of code you're using (i.e. MySQL < 4.1
doesn't support subselects). So as long as you stay with this, you
could be OK.

However, this only applies to data definition language (DDL) statements
such as CREATE TABLE, and data manipulation language (DML) statements
such as SELECT and INSERT. It does not apply to database specific
things like configuration parameters. These are outside of the SQL
language, and anything supported by the database is for your convenience
only and probably not supported by other databases.

However, I question why you'd even use ODBC. If you're using PHP,
Pear::MDB is much faster and more flexible. It also runs well on every
platform, unlike ODBC.

But personally when I need both, I just encapsulate the
database-specific code in PHP classes and select which class I want.
But then all of my DB-specific code is generally in classes anyway.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 30 '06 #2
Jerry Stuckle a écrit :
Jacques Lebastard wrote:
>>
I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')

I'd like to have a single syntax for both databases. Is this possible?
Do I need to modify either database configuration settings? Does each
database (MySQL, PGSQL, MSSQL, Oracle, ...) use its own SQL syntax?

Any advice welcome.
Both MySQL and Postgres support standardized SQL constructs, within the
restrictions of the release of code you're using (i.e. MySQL < 4.1
doesn't support subselects). So as long as you stay with this, you
could be OK.

However, this only applies to data definition language (DDL) statements
such as CREATE TABLE, and data manipulation language (DML) statements
such as SELECT and INSERT. It does not apply to database specific
If they are supposed to support the same syntax, why does Postgres
require table name with double quotes whereas I get an error using
double quotes when accessing a MySQL DB? Is it a PHP issue, an ODBC
driver issue?
things like configuration parameters. These are outside of the SQL
language, and anything supported by the database is for your convenience
only and probably not supported by other databases.

However, I question why you'd even use ODBC. If you're using PHP,
Pear::MDB is much faster and more flexible. It also runs well on every
Humm... pear.php.net seems offline... I'll try later.
platform, unlike ODBC.

But personally when I need both, I just encapsulate the
database-specific code in PHP classes and select which class I want. But
I do have classes to access either LDAP directories, CVS & RAW files,
ODBC databases and other specific storage media. I thought I could
access all databases using a single ODBC class (instead of using
php_mysql, php_oci8, php_pg, ...). Maybe I was naive..
then all of my DB-specific code is generally in classes anyway.
I'll have a look at the MDB package as soon as the site is reachable.

Thanks for your advice,
Oct 1 '06 #3
C.
Jerry Stuckle wrote:
Jacques Lebastard wrote:

I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')
INSERT INTO MyTable (col1, col2) VALUES ('value1','value2')

Should work on both.
>
However, I question why you'd even use ODBC. If you're using PHP,
Pear::MDB is much faster and more flexible. It also runs well on every
platform, unlike ODBC.
Alternatively use the dbx_ functions which support several DBMS, or the
adodb class.

C.

Oct 1 '06 #4
Jacques Lebastard wrote:
Jerry Stuckle a écrit :
>Jacques Lebastard wrote:
>>>
I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')

I'd like to have a single syntax for both databases. Is this possible?
Do I need to modify either database configuration settings? Does each
database (MySQL, PGSQL, MSSQL, Oracle, ...) use its own SQL syntax?

Any advice welcome.


Both MySQL and Postgres support standardized SQL constructs, within
the restrictions of the release of code you're using (i.e. MySQL < 4.1
doesn't support subselects). So as long as you stay with this, you
could be OK.

However, this only applies to data definition language (DDL)
statements such as CREATE TABLE, and data manipulation language (DML)
statements such as SELECT and INSERT. It does not apply to database
specific


If they are supposed to support the same syntax, why does Postgres
require table name with double quotes whereas I get an error using
double quotes when accessing a MySQL DB? Is it a PHP issue, an ODBC
driver issue?
Double quotes are not valid SQL syntax. Not using the ODBC interface
with Postgres, where does it require double quotes?
>things like configuration parameters. These are outside of the SQL
language, and anything supported by the database is for your
convenience only and probably not supported by other databases.

However, I question why you'd even use ODBC. If you're using PHP,

>Pear::MDB is much faster and more flexible. It also runs well on every


Humm... pear.php.net seems offline... I'll try later.
>platform, unlike ODBC.

But personally when I need both, I just encapsulate the
database-specific code in PHP classes and select which class I want. But


I do have classes to access either LDAP directories, CVS & RAW files,
ODBC databases and other specific storage media. I thought I could
access all databases using a single ODBC class (instead of using
php_mysql, php_oci8, php_pg, ...). Maybe I was naive..
Nope, ODBC never has lived up to its promise of complete transparency.
>then all of my DB-specific code is generally in classes anyway.
I'll have a look at the MDB package as soon as the site is reachable.

Thanks for your advice,
It's still not perfect, but better than ODBC, IMHO.

But I still just use my own classes. Much faster and not all that hard
to do.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 1 '06 #5

C. wrote:
>
INSERT INTO MyTable (col1, col2) VALUES ('value1','value2')

Should work on both.
Except on numbers? I read quoting number values in an SQL statement is
not standard (and optional on MySQL).

Larry

Oct 1 '06 #6
la***@portcommodore.com wrote:
C. wrote:
>>INSERT INTO MyTable (col1, col2) VALUES ('value1','value2')

Should work on both.


Except on numbers? I read quoting number values in an SQL statement is
not standard (and optional on MySQL).

Larry
No. Numbers are not quoted in MySQL, per the SQL standard.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 1 '06 #7
I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')
You can run the second line in MySQL also - when you are running the
server in ANSI mode.
I'd like to have a single syntax for both databases. Is this possible?
I think the SQL standard version of the above statements is:

INSERT INTO MyTable(col1, col2) VALUES ('value1','value2')

(Actually, the SQL version is without the columns, but most SQL
databases support the column list)
It would surprise me if PostGress would not understand this statement.

Best regards
Oct 1 '06 #8
Dikkie Dik wrote:
>I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')


You can run the second line in MySQL also - when you are running the
server in ANSI mode.
>I'd like to have a single syntax for both databases. Is this possible?


I think the SQL standard version of the above statements is:

INSERT INTO MyTable(col1, col2) VALUES ('value1','value2')

(Actually, the SQL version is without the columns, but most SQL
databases support the column list)
It would surprise me if PostGress would not understand this statement.

Best regards
Actually, the SQL standard makes the column list optional. If not
specified, you must provide values for all columns in the order in which
they are defined.

Column and table names, per the standard, are not surrounded by quotes.
Non-numerical values are surrounded by single quotes. Numeric values
also have no quotes.

MySQL extends the standard by optionally allowing back tickeys (`)
around table and column names. This allows you to specify names which
would otherwise be forbidden as they are keywords in MySQL. But for
non-keyword names, the back tickeys are not required (but allowed if used).

The correct MySQL version would be:

INSERT INTO MyTABLE (col1, col2) VALUES ('value1', value2);

Assuming value1 is non-numeric and value2 is numeric.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 2 '06 #9
On Sun, 01 Oct 2006 12:02:53 +0200, Jacques Lebastard
<ja***************@free.frwrote in
<45***********************@news.free.fr>:
>Jerry Stuckle a écrit :
>Jacques Lebastard wrote:
>>>
I have a problem writing PHP ODBC scripts that suit both MySQL and
PostgreSQL. So far, the following syntaxes seem to apply to each
database (this is an 'insert' example; the same differences apply to
'select commands):

MySQL: INSERT INTO MyTable (col1, col2) VALUES ("value1","value2")
PGSQL: INSERT INTO "MyTable" (col1, col2) VALUES ('value1','value2')
[snip]
>If they are supposed to support the same syntax, why does Postgres
require table name with double quotes whereas I get an error using
double quotes when accessing a MySQL DB? Is it a PHP issue, an ODBC
driver issue?
They are required because the table name was created as a "quoted
identifier" (possibly by your admin tool). See the PostgreSQL FAQ:
<http://www.postgresql.org/docs/faqs.FAQ.html#item4.21>. Also see the
docs on identifiers:
<http://www.postgresql.org/docs/8.0/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS>.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
Oct 4 '06 #10

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

Similar topics

2
by: Marek Kotowski | last post by:
Hi, I am new to MySQL and PHP programming. What is the practical difference between MySQL ODBC functions (3.51 Driver) and native mysql support in PHP (I mean "mysql_" functions available in...
10
by: callmebill | last post by:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I started on Windows, and it went smoothly enough due to the ODBC stuff that apparently is native to Python at least on windows...
33
by: Joshua D. Drake | last post by:
Hello, I think the below just about says it all: http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg Sincerely, Joshua Drake
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...
9
by: Greg Gursky | last post by:
Hello: I'm doing some planning on a potential project with which I need some help. The database at the focus of this question is a MS Access database that is currently accessed by DAO from a...
4
by: pu | last post by:
Hi, Could any one tell me what the following messages means please? And where can I get the error messages with their descriptions? ===begin=== ODBC --call failed. blank (#110) ===end=== I...
1
by: Maileen | last post by:
Hi, I'm writing a VC++.net 2005 application and i would like to use the ODBC connector. I would like to allow user to choose the DB he wants to have (MS SQL, PostgreSQl, MySQL, Oracle,...) by...
2
by: nishi.hirve | last post by:
Hello, I want to use postgreSQL database in my C++ .NET application but when I try to connect to it, through connect to database, it is shows dialog box as follows: Unable to connect to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.