Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php MSSQL connection issues

Status
Not open for further replies.

deepsheep

Programmer
Sep 13, 2002
154
CA
I've got a master MSSQL database that I am using to determine which other databases (and sql servers) I need to get a summary from.
I need to display summaries from about 10 databases on one php page.
I'm getting an error after 3 of the database summaries are displayed. It seems the result is getting overwritten, but I can't see the typo. the error is:

Warning: mssql_fetch_array(): 3 is not a valid MS SQL-result resource in d:\InetPub\ on line 26

Warning: mssql_close(): 2 is not a valid MS SQL-Link resource in d:\InetPub\ on line 63

Here is the the code, I've stripped out the data display stuff.


$dbname="mastertable";
$dbServer="sqlserver";
$userName="sqluser";
$sqlpassword="password";
$db=mssql_connect($dbServer, $userName, $sqlpassword) or die("unable to connect");
mssql_select_db($dbname) or die("db Unavailable");

$query=" select dbase ,server,dbuser, clientname from ClientRecs order by dbase";


$bresult=mssql_query($query, $db);
while ($row=mssql_fetch_array($bresult) ){ //line 26
$dbname2=$row['dbase'];
$dbServer2=$row['server'];
$userName2=$row['dbuser'];
$clientName=$row['clientname'];
$password2="password";



$db2=mssql_connect($dbServer2, $userName2, $password2) or die("unable to connect");
mssql_select_db($dbname2) or die("db Unavailable");
$query2="SELECT * FROM UnitTable WHERE (UpdateTime < DATEADD(day, - 7, GETDATE())) ";
$result2=mssql_query($query2, $db2);
while ($row2=mssql_fetch_array($result2) )
{
//Display data
}

mssql_close($db2);

}
mssql_close($db); //line 63


Please help!!
 
The errors you are receiving are because of a failed query, so it would seem that there is an error in your SQL SELECT statement when it gets to the fourth db. Add some error checking to this line:
Code:
$result2=mssql_query($query2, $db2);
 
I've managed to fix my problem. It just wanted me to use mssql_pconnect.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top