none
sqlsrv PDO not executing queries

    Question

  • I am following the blog post found here 

    http://blogs.msdn.com/b/sqlphp/archive/2010/08/04/microsoft-drivers-for-php-for-sql-server-2-0-released.aspx 

     

    to use PDO with PHP to access the PHP database. the sample code provided in the blog,

    $serverName = "(local)\sqlexpress"; 
    
     /* Connect to SQL Server using Windows Authentication. */ 
     $conn = new PDO("sqlsrv:server=$serverName;Database=AdventureWorks","",""); 
    
     /* Get products by querying against the product name.*/ 
     $tsql = "SELECT ProductID, Name, Color, Size, ListPrice FROM Production.Product"; 
    
     /* Execute the query. */ 
     $getProducts = $conn->query( $tsql ); 
    
     
     /* Loop thru recordset and display each record. */ 
     while( $row = $getProducts->fetch( PDO::FETCH_ASSOC ) ) 
     { 
      print_r( $row ); 
     } 
    
     /* Free the statement and connection resource. */ 
     $getProducts = NULL; 
     $conn = NULL; 
    


    does not seem to work. the $getProducts variable is not a proper value, and we are failing when trying to call the fetch() function farther down. results in the following error  

     Call to a member function fetch() on a non-object in (site)   

     

    Other similar queries that should work also fail to go through. anyone know what the problem might be?

    Friday, June 17, 2011 5:24 PM

Answers

All replies