1

I am trying to connect and select all fields on the Sales Invoice Header table and echo only the 'No_' field. I am using php with the sqlsrv extension. When I run it I get this error:

Array ( [0] => Array ( [0] => 42S02 [SQLSTATE] => 42S02 [1] => 208 [code] => 208 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid object name 'CRONUS Ísland hf_$Sales Invoice Header'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid object name 'CRONUS Ísland hf_$Sales Invoice Header'. ) )

but the table name is spelled correctly.

here is my code:

<?php
  $serverName = 'SP-101';
  $connectionInfo=array('Database'=>'Demo Database NAV (7-1)');
  $conn = sqlsrv_connect ($serverName, $connectionInfo);

  if($conn == TRUE) {                   
    echo 'Connected';
  }else{
  echo 'Connection failed<br />';
  die(print_r(sqlsrv_errors (), TRUE));
  }

  $sql = 'SELECT * FROM "CRONUS Ísland hf_$Sales Invoice Header"';
  $stmt = sqlsrv_query($conn, $sql);

  if($stmt == false){
    die(print_r(sqlsrv_errors(), TRUE));
        }

  while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    $no = 'No_';
    echo $row[$no];
  }
?>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

your table name has spaces and accent character, you need to enclose the table name in square brackets like

select * from [CRONUS Ísland hf_$Sales Invoice Header]
vishwakarma09
  • 254
  • 3
  • 17
  • man it working on mine, I am getting output Connected Notice: Undefined index: No_ in C:\xampp\htdocs\dbf\mssql.php on line 22 – vishwakarma09 Dec 12 '16 at 15:27