Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting metadata from table sql server (php)

Tags:

php

sql-server

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?

like image 786
Tiago Avatar asked Feb 13 '23 01:02

Tiago


2 Answers

You probably got

sql_variant

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

VARCHAR

like image 132
Xatenev Avatar answered Feb 23 '23 15:02

Xatenev


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?

like image 22
Tiago Avatar answered Feb 23 '23 15:02

Tiago