Data retrieval from SQLserver results in "Invalid column name 'N'"

Asked 2 years ago, Updated 2 years ago, 77 views

We are participating in the development of improved versions of existing services that have already been developed and operated.In order to create a development environment on the local PC, we cloned the source code of existing services created by FuelPHP and created the following virtual environments using Virtual box+vagrant installed on Windows:

  • CentOS 7.4
  • Apache 2.4.6
  • PHP 7.3.22
  • Microsoft SQL server 2017

Installing Microsoft ODBC driver 17 for SQL server in a virtual environment to connect to DB.We also received DB test data (.bacpac file) used in the development environment of existing services and imported data from SQL Server Management Studio.

After creating the development environment as described above, you can access http://192.168.33.10 to see the front page.From there, when I logged in to transition to the service administrator screen, the following error occurred and the screen transition was not completed.Also, the screen after the transition is a screen that reads and displays data lists of managed users from DB.

Fuel\Core\Database_Exception [42S22(207)]:
SQLSTATE [42S22]: Column not found: 207 [Microsoft] [ODBC Driver 17 for SQL Server] [SQL Server]Invalid column name 'N'. (SQLExecute[207] at /builddir/build/BUILD/php-7.3.22/ext/pdo_odbc/odbc_stmt.c:259) with query: "SELECT t0.id AS t0_c0, t0.grouping_id AS t0_c1, t0.watcher_id AS t0_c2,... (以下同じように続くので中略)...t2.updated_at AS t2_c15 FROM grouping_watchers AS t0 LEFT JOIN groupings AS t1 ON (t0.grouping_id = t1.id) LEFT JOIN watchers AS t2 ON (t0.watcher_id = t2.id) WHERE t2.account_id = N"

I'm sorry that the contents of the error are getting longer, but I think it's a Invalid column name 'N' error.I understand that SQLserver puts 'N' on the head when inserting Japanese characters, but I don't know how to resolve this error.

Note:
Inserting Japanese data into SQLServer causes garbled characters.

It may be a difficult question to answer because there is not much information, but I would appreciate it if you could let me know if there are any hints or good things to try.Thank you for your cooperation.

sql-server

2022-09-30 15:02

2 Answers

If you fold back the error message properly,

"SELECT t0.id AS t0_c0, t0.grouping_id AS t0_c1, t0.watcher_id AS t0_c2, ... (abbreviated as it continues the same way below) ...t2.updated_at AS t2_c15
 FROM grouping_watchers ASt0
 LEFT JOIN groups AS t1 ON (t0.grouping_id=t1.id)
 LEFT JOIN watchers AS t2 ON (t0.watcher_id=t2.id)
 WHERE t2.account_id=N"

It seems that the SQL statement ends with N because it is bound by "In the first place, regardless of Japanese, is this an intended SQL statement?

You should not worry about adding a N prefix to SQL statements, as the variable portion typically uses prepared statement.


2022-09-30 15:02

I understand that you are using PHP, so please check the following points.

1) Isn't the part where the SQL is created concatenated by string concatenation?

PHP also

$sth=$dbh->prepare('SELECT*)
    FROM grouping_watchers
    WHERE WHERE account_id=?');

It is recommended to parameterize using ? as shown in .
Looking at the events that have occurred, there seems to be a SQL injection vulnerability.

2) Clone the source code of the existing service. In the case of git, there is a CRLF automatic conversion setting for the new line code, so
Wrong line feed code for apps running on Linux to CRLF
It may be that ...

Even if the new line code is different, it works if it works, but sometimes it doesn't work...

Please check these two points.


2022-09-30 15:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.