Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2008, 08:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default MySQL Stored procs with ASP

Hi All,

I am looking at stored procs with mySQL 5 and have managed to create a simple stored proc myself as there doesn't seem to be alot out there with mysql and classic ASP. Im wondering how you pass variables through a stored proc? My simple select works fine. I quick run through would be much appreciated.

Tim :)
Code:
MY PROC
CREATE PROCEDURE `pc_getAccounts`()
    READS SQL DATA
SELECT * FROM accounts
MY ASP Page
[code]


<%

' call stored proc
strSQL = "CALL pc_getAccounts;"
Set objRS = objConn.Execute("call pc_getAccounts()")

Do While not objRs.EOF
    Response.Write objRS("FirstName") & "<BR>"
    Response.Flush()
    objRS.MoveNext
Loop

%>

[/code

TDA
__________________
TDA
 
Old June 16th, 2008, 09:36 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Two ways:

(1) Using ADODB.Command and ADODB.Paremeter objects, which create by calling commandObject.CreateParameter and then add to the command using commandObject.Append

You can check out examples and docs here:
http://msdn.microsoft.com/en-us/library/ms677209(VS.85).aspx
(That's a jump into the middle of the stuff, but perhaps the first thing to see.)

(2) The quick and dirty way.
Code:
CREATE PROC foo 
    @param1 INT,
    @param2 VARCHAR(30)
AS 
   ...
And then invoke it via:
Code:
<%
SQL = "CALL foo( 17, 'zamboni' )"
Set RS = yourConnectionObject.Execute( SQL )
%>
************
CAUTION: That second way is STILL subject to SQL injection! You *NEED* to sanitize all parameters.

So of course the right thing to do is method 1, even if it is a pain.
 
Old June 17th, 2008, 12:09 AM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Thanks for the reply.

I will definately look at the correct way to do it, however im still coming to grips with the mySQL part so i will do the short way to get the concepts.

Its definately put me on the right track. However is the stored proceedure a mySQL as i found i need to create variables in a different way. However the funny thing is my store proc works with no errors but shows all results instead of just the 1 record with the id of 17. What have i done wrong?

Apreciate your help :)

Code:
' call stored proc
PersonID = 17
Set objRS =  objConn.Execute("call getAccount("&PersonID&")")

Do While not objRs.EOF
    Response.Write objRS("FirstName") & "<BR>"
    objRS.MoveNext
Loop
MY PROC

Code:
CREATE PROCEDURE `getAccount`(IN PersonID INT)
SELECT * FROM accounts where PersonID = PersonID;
TDA
 
Old June 17th, 2008, 12:35 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Might just be because you use the same name!

After all, if there was no parameter in use, this statement *WOULD* be expected to get *ALL* records:
    SELECT * FROM accounts where PersonID = PersonID;

Because, indeed, for every record, the value of PersonID *WILL* be the same as the value of ... PersonID!

I've created several MySQL procedures, but I've always carefully avoided overlap of names. So all I can say is that doing so seems to work!
Code:
CREATE PROCEDURE `getAccount`(IN ID INT)
SELECT * FROM accounts where PersonID = ID;
Betcha it then works!
 
Old June 17th, 2008, 01:20 AM
Authorized User
 
Join Date: Jun 2003
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

haha yep your spot on! Cheers thanks for all your help

Tim :)

TDA





Similar Threads
Thread Thread Starter Forum Replies Last Post
O/R mappers vs stored procs rocco50 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 June 9th, 2007 07:49 AM
undocumented stored procs priyaram SQL Server 2005 0 February 21st, 2007 12:24 PM
Problems with Reports based on Stored Procs skiskis Access 2 September 7th, 2005 02:23 PM
Informix stored procs from ADO tomRA Access 0 October 28th, 2004 09:45 AM
Transactions in C#, not stored procs organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 6 October 10th, 2004 09:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.