1. 程式人生 > >TP 框架解決Unknown column 'XXX' in 'where clause' 問題

TP 框架解決Unknown column 'XXX' in 'where clause' 問題

最近在使用TP框架開發公司網站,遇到了一個問題Unknown column 'XXX' in 'where clause'的問題。

這個問題最初查詢使用者的個人資訊,分別通過使用者的手機號和郵箱查詢:

1.手機號查詢

$mobile = (string)'手機號XXX';

$user = M('ey_user')->where('phone='.$mobile)->find();

var_dump($user);

可以查詢出資料。

2.郵箱查詢

$mobile = (string)'[email protected]';

$user = M('ey_user')->where('phone='.$mobile)->find();

var_dump($user);

查詢的結果:


我懷疑是由於TP框架或者是Mysql對於‘@’有什麼特殊編碼要求,然而並不是。我嘗試使用數字和字串查詢,數字沒有問題,但是字串就會出現問題。

根據對打印出來的bug定位,分別對框架中的程式碼,進行分析最終列印“Driver.class.php  LINE: 352”資料庫的程式碼。


列印結果是“Unknown column 'XXX' in 'where clause”。

針對Mysql 出現“Unknown column 'XXX' in 'where clause”錯誤,存在兩個種可能出現錯誤的原因:

1)資料庫的資料表種“ column 'XXX' ”不存在,但是這種情況一般很少會出現。

****2)資料庫無法識別“XXX字串”,無法正確解析字串。所以我們要把查詢的內容轉化成字串型別**********

$mobile = (string)'[email protected]';

$user = M('ey_user')->where('phone=\''.$mobile.'\'')->find();

var_dump($user);

在字串上新增單引號,使用String並沒有什麼效果。

Unknown column 'XXX' in 'where clause:

      1)檢查字串新增單引號,轉化成字串型別(Mysql無法解析模糊的型別)

      2)檢查資料庫的表中是否存在xxx的行


有什麼問題和不同的意見歡迎留言討論

相關推薦

TP 框架解決Unknown column 'XXX' in 'where clause' 問題

最近在使用TP框架開發公司網站,遇到了一個問題Unknown column 'XXX' in 'where clause'的問題。這個問題最初查詢使用者的個人資訊,分別通過使用者的手機號和郵箱查詢:1.手機號查詢$mobile = (string)'手機號XXX';$user

MySql報錯原因分析Unknown columnxxxinwhere clause

在更新資料庫時曾經碰到過類似於Unknown column ‘xxx’ in ‘where clause’的問題。 單從字面理解,我們很容易得出列名不存在的結論,但是,很多時候起始並不是由於列名出

Sql語句錯誤 Unknown column xxx in where clause

Sql語句錯誤 但凡寫過sql語句的人估計都曾經碰到過類似於Unknown column ‘xxx’ in ‘where clause’的問題。 單從字面理解,我們很容易得出 列名不存在的結論,但是,很多時候起始並不是由於列名出錯造成的。而是由於拼湊sq

Unknown column 'rownum' in 'where clause'解決方案

Unknown column 'rownum' in 'where clause',當在巢狀的查詢語句裡面用到rownum的時候會遇到這個問題,比如: SELECT * FROM  (select t.id,t.name from USER_INFO t where t.s

python操作資料庫出現錯誤 : Unknown column 'XXXX' in 'where clause'")錯誤

今天練習的時候,出現了這種坑爹的錯誤,找了好久,終於知道錯誤原因了,貼出修改的地方 在MySQL資料庫中存在中文的字元,python操作資料庫的語句如下 sql = "select * from t

mysql Column 'dbvalue' in where clause is ambiguous解決方案

在一次使用mysql資料庫查詢的時候出現錯誤提示 Column 'languageid' in where clause is ambiguous,這個錯誤in where clause is amb

mysql下出現Unknown column 'id' in 'on clause'的解決方法

select vinfo.vid_id, vid_name, vid_leadrole, vid_desc, vid_director, vid_date,  vid_area, vid_pic, vid_score, vid_info, vinfo.cid, vid_ser

java開發常遇錯誤:Column 'AAA' in where clause is ambiguous解決辦法

當在java開發中遇到了Column ‘AAA’ in where clause is ambiguous問題時,你需要去看看:多表查詢的時候不同的表是否出現了相同名稱相同的列,如果存在,你需要在條件中或者查詢結果中指定表名比如:user表有name,post表

Unknown column 'xxx' in 'field list'

MySQL資料庫插入資料時,出現Unknown column 'XXX' in 'field list' 問題('XXX'表示任意字元)。例如下面: 先建立一個數據庫:CREATE TABLE `p

連線查詢 Error:Column 'XXX' in order clause is ambiguous

錯誤為: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'XXX' in order clause is ambiguous↵ ### T

MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous; SQL []; Colu

dede(織夢)從5.5升級到5.6出現的“Unknown column 'weight' in 'field list'”的問題的解決辦法

Technorati 標籤: dede,織夢,5.5,5.6,錯誤,weight     此問題是由於資料表中缺少“weight”欄位導致的,所以解決辦法自然是修復出現問題的“dede_archives”表,下面有兩種途徑可以解決: 1、到dede官網下載5.5到5.6的升級

遷移檔案是報錯 django.db.utils.InternalError: (1054, "Unknown column 'name' in 'django_content_type'")

相信大家在做django遷移時有可能會遇到這樣的錯誤- django.db.utils.InternalError: (1054, “Unknown column ‘name’ in ‘django_content_type’”) 這個也是我遇到過得問題,

Unknown column 'name' in 'field list' 的小坑

在 使用mybatis對資料庫資料進行修改的時候出現瞭如下錯誤: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: com.mysql.jdbc.

MySQL5.7更改密碼時出現ERROR 1054 (42S22): Unknown column 'password' in 'field list'

新安裝的MySQL5.7,登入時提示密碼錯誤,安裝的時候並沒有更改密碼,後來通過免密碼登入的方式更改密碼,輸入update mysql.user  set password=password('root') where

SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' -- IF查詢出錯

mysql IF() 查詢的時候出現這個錯誤 場景: user表 age欄位,查詢並輸出欄位 is_adult (0表示未成年,1表示已成年) 查詢語句如下: SELECT IF( age&g

mybaits錯誤 MySQLIntegrityConstraintViolationException: Column 'name' in where clause is ambiguous

dispatch tin lse rep thread sta RoCE .data cti 五月 06, 2019 1:50:36 上午 org.apache.catalina.core.StandardWrapperValve invoke嚴重: Servlet.ser

【MySQL 線上 BUG 分析】之 多表同欄位異常:Columnxxxin field list is ambiguous

一、生產出錯! 今天早上11點左右,我在工作休息之餘,擼了一下貓。突然,工作群響了,老大在裡面說:APP出錯了! 媽啊,這太嚇人了,因為只是說了出錯,但是沒說錯誤的資訊。所以我趕緊到APP上看看。 這果然是出錯了,而且還是簡單而粗暴的500,太嚇人了。 二、本地趕緊除錯起來! 既然線上出錯了,我們又不

mybatis+mysql 關於兩個張表有相同屬性名查詢報錯的原因Column 'id' in order clause is ambiguous

mybatis+mysql 關於兩個張表有相同屬性名查詢會報錯的 注意,在MYSQL Wordbench中查詢時是可以通過的。 在mybatis中查詢兩張表中有相同屬性名會報錯 t_class表                                     

java.lang.Exception: 資源處理失敗,失敗原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '?????‰' in 'where clause'

exception 替換 div name jdbc unknown syn lan -s 1:Unknown column ‘?????‰‘ in ‘where clause‘,這個問題,百度一搜,挺多的,但是貌似好像沒有解決我的問題。貼一下我是如何拼接sq