column with invalid accent

Asked

Viewed 473 times

0

I’m assembling a report using the database of a system and PHP with DBLIB, however, who structured the database created the tables and fields accentuated. When I go to make a query in some field that has not accentuated the query works, but when accent has gives invalid column error.

Example:

 select CAST(cp.[vencimento] AS date) as vencimento from contaspagar as cp;  //essa funciona de boa
 select CAST(cp.[dataemissão] AS date) as dataemissao from contaspagar as cp; //essa da erro de coluna invalida

I’m using Linux, PHP 5.6, and the freetds library to connect to SQL, SQL 2008 express.

Error in PHP:

SQLSTATE[HY000]: General error: 207 General SQL Server error: Check messages from the SQL Server [207] (Severity 16) [(null)]NULL

Meaning of error:

Invalid column name '%. *ls'.

  • 1

    Post the exact error message please.

  • Does Ygor have any way of telling you exactly what is happening? If we inform you, we may be able to guide you to make it work.

  • @Guilherme-birth I am mounting a screen in PHP to generate a report, I can already connect to the database and run some query, but some tables in the database have accentuation and when I run the query by PHP tells that the column is with invalid name, but if I run the direct query in management it runs normally

  • But put the error exactly, if the exact error message we have no way to deduce anything.

  • put in question

2 answers

2

Solution:

$query=iconv( 'UTF-8', 'Windows-1252', $query );

Connection to DBMS is not UTF-8. Freetds is Ansi/Windows 1252.

2

When the name of the identifiers (tables columns ect) have accented characters or other types use the escapes, in the case of SQL SERVER are square brackets ([])

Change:

SELECT descrição FROM ...

To:

SELECT [descrição] FROM ...
  • tried so:select CAST([cp.date issuance] AS date) the date issuance and so: select CAST(cp.[date issuance] AS date) the date issuance gave invalid column name

  • @Ygoranjos It must be so: select CAST(cp.[dataemissão] AS date) as dataemissao the mattresses are individual or goes for each column

  • tried, same error :( .... direct in Servemanagement works, when I put in PHP error

  • @Ygoranjos what error? in SQL Management also gives this error?

  • SQLSTATE[HY000]: General error: 207 General SQL Server error: Check messages from the SQL Server [207] (Severity 16) [(null)]NULL Invalid column name '%. *ls'.

  • when I put another field without accentuating in the brackets it performs

  • @Ygoranjos may be problem in the rest of the query, add it in the question.

  • the rest is ...from table as cp

  • @Ygoranjos when you print your select by php (if you haven’t tested this, do it) does it print right? or does it show strange characters in accents?

  • was one of the first things I tested, I’m using PDO, will change anything?

  • @Ygoranjos puts the full select here.

  • put in question

  • @Ygoranjos try it alone select CAST([dataemissão] AS date) as dataemissao from contaspagar as cp or select CAST(contaspagar.[dataemissão] AS date) as dataemissao from contaspagar

  • the same mistake is happening

Show 10 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.