[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name

Viewed 3817

I want to access the MS SQL Server and have the select query. I have installed the dll files and am using the sqlsrv_query. The connection has been successful but I get:

[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name as error

I am using PHP version 5.3.1

After the connection I have this code

$sql = "SELECT id, latitude, longitude from job ";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
      echo $row['latitude'].", ".$row['longitude']."<br />";
}
sqlsrv_free_stmt( $stmt);
3 Answers

Try to execute using the Database and Schema names like

databaseName.schema.table

$sql = "SELECT id, latitude, longitude from [DB_Name].[dbo].[job]";

OR

only with schema name: DBO or any other

$sql = "SELECT id, latitude, longitude from [dbo].[job] ";
Related