Jump to content

Recommended Posts

Hi Everyone,

I have this php page that runs couple of MS SQL stored procedures to fetch me values from SQL Server, however I have run into a problem where not more then 2 stored procedures are executed at same time. For instance below mentioned code only fetches me values for 1st and 2nd SP's. If I need values from the 3rd stored procedure then I would have to comment either one of the first two stored procedure.

 

Can someone please tell me what is that I am doing wrong.

 

I am relatively new to PHP, so please be gentle. :)

Any help would be highly appreciated.

Thanks.

<?php


if($conn = mssql_connect('host', 'user', 'pass')) echo 'Connected to SQLEXPRESS<BR>';
if(mssql_select_db("database",$conn)) echo 'Selected DB: SomeDatabase<BR>';

$variable1=something;

$sql_statement =  mssql_init("stored_procedure1 '$variable1'", $conn);
$result=mssql_execute($sql_statement);

$x=0;

while ($row = mssql_fetch_assoc($result))
    {
    $column2[$x]= $row['column2'];
    $column1= $row['column1'];
    
$x++; }

    
echo "Value 1: $column1      </br>";
echo "Value 2: $column2[0]  </br>";
echo "Value 3: $column2[1]  </br>";
echo "Value 4: $column2[2]  </br>";
echo "Value 5: $column2[3]  </br>";
echo "Value 6: $column2[4]  </br>";
echo "Value 7: $column2[5]  </br>";


mssql_free_statement($sql_statement);



$sql_statement =  mssql_init("stored_procedure2 '$variable1'", $conn);
$result=mssql_execute($sql_statement);


$x=0;

while ($row = mssql_fetch_assoc($result))
    {
    $someval1[$x]= $row['somecolumn1'];
    $someval2[$x]= $row['somecolumn2'];
    $someval3= $row['somecolumn3'];
    $someval4= $row['somecolumn4'];
    $someval5= $row['somecolumn5'];
    $someval6= $row['somecolumn6'];

$x++; }

    
echo "Something1: $someval1[0]</br>";
echo "Something2: $someval3 </br>";
echo "Something3: $someval2[0] </br>";
echo "Something4: $someval4 </br>";
echo "Something5: $someval6 </br>";
echo "Something6: $someval5 </br>";


mssql_free_statement($sql_statement);


$sql_statement =  mssql_init("stored_procedure3 '$variable1'", $conn);
$result=mssql_execute($sql_statement);


$x=0;

while ($row = mssql_fetch_assoc($result))
    {
    $somevaluecheck= $row['somecolumncheck'];

$x++; }
    
echo "SomethingCheck: $somevaluecheck </br>";


mssql_free_statement($sql_statement);


?>
Link to comment
https://forums.phpfreaks.com/topic/290104-php-ms-sql-stored-procedure/
Share on other sites

  • Solution

try using @mysql_free_result();

 

some good tips

- dont name all your querys the same number or letter them like $query1,$query2 ect. this would also apply to the $result

- free the $result not the query this releases the resource from the database

 

give these tips a try and it should start working

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.