4

I'm trying to get metadata from the tables on my database (sql server). I execute the query to get that metadata on Sql Management Studio and it works but on php script show that error when i do : $row=sqlsrv_fetch_array($res): "Unexpected SQL type encountered in calc_string_size."

I suspected that the problem was on the build of the query string on the php but it's not because i printed that query and it's correct.

The problem appears when i added a field on the select (column description).

Anyone know that problem?

Tiago
  • 81
  • 4

3 Answers3

4

You probably got

sql_variant

somewhere in your query. That throws an error -> you have to cast the specific columns as

VARCHAR

Xatenev
  • 6,383
  • 3
  • 18
  • 42
2

First of all thank you for answer.

my code:

$res=sqlsrv_query($conn,$sql); /that part is working/ while($row=sqlsrv_fetch_array($res)){ /* it's here that the error occurs (...) }

On the query sql if i remove the field (description) on select that works 100%

Any ideas?

Tiago
  • 81
  • 4
2

The problem is solved. I did a cast to that description field and it works. For the next people who will try get metadata from a table on sql server and need the description field it's necessary do cast to that field to varchar. Thank you!

Tiago
  • 81
  • 4