0

I'm trying to query the sql server database through php and the field name has an accent and I get the following error.

Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean

the code is:

$sql='SELECT introductión FROM table;              
$stmt = sqlsrv_query($conn,$sql);   
while( $row = sqlsrv_fetch_array( $stmt ) ) {
    echo $row[0];
}
chris85
  • 23,846
  • 7
  • 34
  • 51
  • Is `mysql` related? – chris85 Aug 23 '17 at 17:27
  • 2
    `$sql='SELECT introductión FROM table;` you did forget a quote here if that is your actual code; we don't know that; you do. `$sql='SELECT introductión FROM table';` and make sure you use the right collation for it. – Funk Forty Niner Aug 23 '17 at 17:30
  • we also don't know if `table` is also the actual table name or not; you do. – Funk Forty Niner Aug 23 '17 at 17:32
  • Although a number of answers suggest the `introductión` column needs to be enclosed, that is not the case since it conforms to the regular identifier naming rules (https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers). – Dan Guzman Aug 24 '17 at 01:54

3 Answers3

1

Try this: SELECT [introductión] FROM table;

Bestter
  • 877
  • 1
  • 12
  • 29
1

Try putting the column name in square brackets.

$sql='SELECT [introductión] FROM table';
1

In SQL Server, you can use [] to delimit column (or table, or etc...) names. In MySQL, you typically use the ` (the one on the ~ key).

Uueerdo
  • 15,723
  • 1
  • 16
  • 21