Postgre functions for (Insert, Udate and Delet)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
esales
Forum Newbie
Posts: 2
Joined: Fri Nov 29, 2002 12:38 pm
Location: Brazil - São Paulo

Postgre functions for (Insert, Udate and Delet)

Post by esales »

Dear fellows

Can I put my sql string inside postgresql functions and call them from PHP ?

How should I call it from PHP ?

I'll appreciate any help. Thanks :D
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

From my quick research on building functions for postgreSQL I found it was easier in my case to build a table that held my sql statments along with usage restriction(s) ids that were references to xml definitions responsible for dictating how it was to be used in my system, and this was all called in with a php API i developed that processed the statement based on the definition and acted accordingly.


HOWEVER, :-) if you wanted to build functions, they seem quite basic and are best developed in C/C++ and imported as addtional functionality add-ins. This is all supported by postgreSQL.
esales
Forum Newbie
Posts: 2
Joined: Fri Nov 29, 2002 12:38 pm
Location: Brazil - São Paulo

Post by esales »

MeOnTheW3 wrote:From my quick research on building functions for postgreSQL I found it was easier in my case to build a table that held my sql statments along with usage restriction(s) ids that were references to xml definitions responsible for dictating how it was to be used in my system, and this was all called in with a php API i developed that processed the statement based on the definition and acted accordingly.


HOWEVER, :-) if you wanted to build functions, they seem quite basic and are best developed in C/C++ and imported as addtional functionality add-ins. This is all supported by postgreSQL.
Thank you Jason, but...

When I build a Stored Procedure in SQL Server, for example, to insert some data I do this:

IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'proc_gbl_InsertLogin' AND type = 'P')
DROP PROCEDURE proc_gbl_InsertLogin
GO
CREATE PROCEDURE proc_gbl_InsertLogin
(
@cLoginName VARCHAR(10),
@cPassWord VARCHAR(10),
)
AS
-----------------------------------
--Here I put all my Code
------------------------------------
DECLARE @EXISTLOGIN varchar(10)
DECLARE @HORAH datetime
SELECT @HORAH = GETDATE()
---------------
BEGIN
SELECT @nCodLogin=0;
ETC....

From VB component I can call..

With Cmd
.ActiveConnection = Conn
.CommandText = "proc_gbl_InsertLogin"
.CommandType = adCmdStoredProc
.CommandTimeout = 15
Set Prm = Cmd.CreateParameter("cLoginName", adVarChar, adParamInput, 10, cLoginName)
.Parameters.Append Prm
Set Prm = Cmd.CreateParameter("cPassWord", adVarChar, adParamInput, 10, cPassWordCript)
.Parameters.Append Prm
.Execute
End With
----------------------------------------------------------------------------
In the same way I do this for Delete and Update.Sorry for the long text.
The question is:

How can I build a Stored Procedure (Function) in PostgreeSQL and how can I call it from PHP, what is the sintaxe ?

Of course if the friend have some tutorial or URL to help, it will be great.

Yours sincerely
Post Reply