douchen9855 2014-06-21 22:27
浏览 30

对Azure SQL查询的MySql查询失败

I am trying to move my web site to Azure, and so to rely on their SQL servers, while before I was using Apache/MySql.

I have some difficulties trying to convert the queries, as they do not work anymore.

The following works if i connect to the MySql db, but it fails if I change the connection to the Azure SQL.

string(178) "SELECT * FROM schemedb.users WHERE CreatedBy=20 ORDER BY dateCreation Desc" string(177) "SELECT IdUsr FROM schemedb.userssettings WHERE User=20 ORDER BY Id Desc"

All connections to the Azure SQL server are correct, as a simpler query before these gets executed fine. But then I got stuck here.

The php error console says

Fatal error: Call to a member function setFetchMode() on a non-object in ...

To understand where the problem was I used var_dump on the queries, to see where they were failing, turns out that if I change them to:

string(178) "SELECT * FROM schemedb.users ORDER BY dateCreation Desc" string(177) "SELECT IdUsr From schemedb.userssettings Order By Id Desc"

These queries are then valid, so I guess that the problem is the where clause then, but I have no clue of what's the problem.

-- EDIT

I've made some test, turns out that if I manually write the query, it works as expected.

What I mean is that the above mentioned query is build through several php custom methods like so:

." WHERE ".$this->buildWhere()." ORDER BY ". etc.

But if I type there WHERE CreatedBy = 20, then it works.

My best guess is that it is a format problem, since in SQL Azure the data type in the query must be of the same type of the one declared in the column.

However, I cant' understand what's wrong, since my custom method is writing the value vithout ', therefore as a number, not a string...

  • 写回答

0条回答 默认 最新

    报告相同问题?