dbTalk Databases Forums  

PHP code to Stored Procedure

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss PHP code to Stored Procedure in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
aCe
 
Posts: n/a

Default PHP code to Stored Procedure - 09-22-2007 , 01:57 AM






hi all,
i need to convert these simple PHP code into stored procedure :
<?php
$result = mssql_query( "SELECT whid, whcode FROM warehouse" );
while( $wh = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
'" . $wh->whid . "'";
while( $pl = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
'" . $pl->plid . "'";
while( $pln = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
}
}
?>
my focus is in nested query, then i can call each field from the query
(SELECT whid, whcode...) in sub query.
thanks,
aCe


Reply With Quote
  #2  
Old   
Dan Guzman
 
Posts: n/a

Default Re: PHP code to Stored Procedure - 09-22-2007 , 09:00 AM






Quote:
i need to convert these simple PHP code into stored procedure :
I don't know PHP but you can JOIN the related tables and encapsulate the
query in a stored procedure like the untested example below. You'll often
get best performance by joining related tables on the back-end rather than
performing for-each processing in application code.

CREATE PROCECURE dbo.usp_GetPackingLists
AS
SELECT
w.whcode,
pl.plid,
pln.qty
FROM dbo.warehouse AS w
JOIN packlist AS pl ON w.whid = pl.whid
JOIN packlistnmat AS pln ON pln.plid = pl.plid
GO

<?php
$result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
while( $wh = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
?>

--
Hope this helps.

Dan Guzman
SQL Server MVP



"aCe" <acerahmat (AT) gmail (DOT) com> wrote

Quote:
hi all,
i need to convert these simple PHP code into stored procedure :
?php
$result = mssql_query( "SELECT whid, whcode FROM warehouse" );
while( $wh = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
'" . $wh->whid . "'";
while( $pl = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
'" . $pl->plid . "'";
while( $pln = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
}
}
?
my focus is in nested query, then i can call each field from the query
(SELECT whid, whcode...) in sub query.
thanks,
aCe



Reply With Quote
  #3  
Old   
aCe
 
Posts: n/a

Default Re: PHP code to Stored Procedure - 09-23-2007 , 11:16 PM



On Sep 22, 9:00 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
Quote:
i need to convert these simple PHP code into stored procedure :

I don't know PHP but you can JOIN the related tables and encapsulate the
query in a stored procedure like the untested example below. You'll often
get best performance by joining related tables on the back-end rather than
performing for-each processing in application code.

CREATE PROCECURE dbo.usp_GetPackingLists
AS
SELECT
w.whcode,
pl.plid,
pln.qty
FROM dbo.warehouse AS w
JOIN packlist AS pl ON w.whid = pl.whid
JOIN packlistnmat AS pln ON pln.plid = pl.plid
GO

?php
$result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
while( $wh = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;}

?

--
Hope this helps.

Dan Guzman
SQL Server MVP

"aCe" <acerah... (AT) gmail (DOT) com> wrote in message

news:1190444269.094724.14270 (AT) 57g2000hsv (DOT) googlegroups.com...

hi all,
i need to convert these simple PHP code into stored procedure :
?php
$result = mssql_query( "SELECT whid, whcode FROM warehouse" );
while( $wh = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
'" . $wh->whid . "'";
while( $pl = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
'" . $pl->plid . "'";
while( $pln = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
}
}
?
my focus is in nested query, then i can call each field from the query
(SELECT whid, whcode...) in sub query.
thanks,
aCe
thanks for your reply Dan Guzman.
but my query more complex than above.
coz i'm a newby in MSSQL, i need to optimize my query using stored
procedure.

can help me further more, thx before...



Reply With Quote
  #4  
Old   
Ed Murphy
 
Posts: n/a

Default Re: PHP code to Stored Procedure - 09-24-2007 , 10:29 AM



aCe wrote:

Quote:
thanks for your reply Dan Guzman.
but my query more complex than above.
coz i'm a newby in MSSQL, i need to optimize my query using stored
procedure.

can help me further more, thx before...
Unless you plan on posting the more complex query, I doubt he
can. The telepathic version of MSSQL is still about five years
away from RTM.

(joke stolen from the MAS 90 support forums, obviously can be
applied to any software you like)


Reply With Quote
  #5  
Old   
Dan Guzman
 
Posts: n/a

Default Re: PHP code to Stored Procedure - 09-24-2007 , 08:43 PM



Quote:
thanks for your reply Dan Guzman.
but my query more complex than above.
coz i'm a newby in MSSQL, i need to optimize my query using stored
procedure.
Do you have another query? I included the stored procedure code in my
response based on the queries and code you provided. If you are having
trouble extending the solution, we'll need more information to help.


--
Hope this helps.

Dan Guzman
SQL Server MVP

"aCe" <acerahmat (AT) gmail (DOT) com> wrote

Quote:
On Sep 22, 9:00 pm, "Dan Guzman" <guzma...@nospam-
online.sbcglobal.net> wrote:
i need to convert these simple PHP code into stored procedure :

I don't know PHP but you can JOIN the related tables and encapsulate the
query in a stored procedure like the untested example below. You'll
often
get best performance by joining related tables on the back-end rather
than
performing for-each processing in application code.

CREATE PROCECURE dbo.usp_GetPackingLists
AS
SELECT
w.whcode,
pl.plid,
pln.qty
FROM dbo.warehouse AS w
JOIN packlist AS pl ON w.whid = pl.whid
JOIN packlistnmat AS pln ON pln.plid = pl.plid
GO

?php
$result = mssql_query( "EXEC dbo.usp_GetPackingLists" );
while( $wh = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;}

?

--
Hope this helps.

Dan Guzman
SQL Server MVP

"aCe" <acerah... (AT) gmail (DOT) com> wrote in message

news:1190444269.094724.14270 (AT) 57g2000hsv (DOT) googlegroups.com...

hi all,
i need to convert these simple PHP code into stored procedure :
?php
$result = mssql_query( "SELECT whid, whcode FROM warehouse" );
while( $wh = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT plid, nopl FROM packlist WHERE whid =
'" . $wh->whid . "'";
while( $pl = mssql_fetch_object( $result ) )
{
$result = mssql_query( "SELECT qty FROM packlistnmat WHERE plid =
'" . $pl->plid . "'";
while( $pln = mssql_fetch_object( $result ) )
{
echo "Stock from " . $wh->whcode . " AND Packing List number " .
$pl->plid . " = " . $pln->qty;
}
}
}
?
my focus is in nested query, then i can call each field from the query
(SELECT whid, whcode...) in sub query.
thanks,
aCe

thanks for your reply Dan Guzman.
but my query more complex than above.
coz i'm a newby in MSSQL, i need to optimize my query using stored
procedure.

can help me further more, thx before...



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.