Re: sql command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi Philip,

Could someone explain to me why sql commands work in php with pgsql?

?? Why wouldn't they? :P

I'm too new at this to understand. That's why I ask. What I don't understand is this: is sql generic as opposed to specific comands in mySQL and/or postgreSQL?

SQL is generic and specific. Sorry to be confusing :)

Each database system has a slightly different syntax for things but the basics remain (to give really simple examples) :

INSERT INTO table_name (field1, field2, field3) VALUES (value1, value2, value3) ..
UPDATE table_name SET field1=value1, field2=value2 WHERE field3=value3 ..
DELETE FROM table_name WHERE field1=value1 ..
SELECT field1, field2 FROM table_name WHERE field3=value3 ..

Differences come in with things like auto-increment fields, dates and times.
Example: MySQL uses an 'auto_increment' datatype, PostgreSQL uses a 'serial' datatype.

I now understand that in my problem below you are right, there was an sqlconnect function created as you suggested below. Then, what would be the reason to use this sqlconnect function rather than pg_connect? Can't parameters be passed on to the pg_connect in the same way as they are passed on to the created sqlconnect? It seems like extra work or a bit of redundancy in creating a function that exists?

Sort of right. When you initially set it up, it can be a little bit of extra work, but you can get a lot of advantage (time-saving) out of it.

You can now use it all over the place in your code, without worrying about typos, you know it works and how it works etc. If you want to change it to do something else (eg add logging), you only have to do it in one place, instead of searching through all your code looking for places that need it.

The same reasons for any sort of function in any code exist here :)


-----------------
     Chris Smith
http://www.squiz.net/



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux