I have an application that is writen in PHP and connects to a MS SQL Server 2008 Database. I'm using ADO recordsets. There are cases where specific IDs and years in the table returns nothing. How do I test for when there are no results? I searched and most of the results are when using MySQL but I'm not using that. Here's a sample of my code:
$myServer = "localhost"; $myUser = "user"; $myPass = "password"; $myDB = "myDatabase"; //create an instance of the ADO connection object $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; //define connection string, specify database driver $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; $conn->open($connStr); //Open the connection to the database //declare the SQL statement that will query the database $query = "Select from tblName where id='10' and year='2010'"; //execute the SQL statement and return records $rs = $conn->execute($query); if(!is_null($rs->Fields)) echo 'We have something here <br>' else echo 'We have a null <br>'