Loading...

PDO PHP - PDOException - Numeric value out of range: 1264 Out of range value for column user_ip at row 1

Temperature: 0 °C

Mark ChangMark Chang
author_tools

最近遇到一個問題,一個Mysql的錯誤訊息。

我想要紀錄一個IP資訊,我會先用以下方式擷取用戶端使用者IP

sprintf("%u", ip2long($_SERVER['REMOTE_ADDR']))

然後再把資訊存入到Mysql...

在測試端時我測試一切正常,但在客戶端卻出現500的錯誤訊息且錯誤代碼1264。

原因是客戶端使用的IP是IPV6,長度較長,這點我倒是沒考慮到。

所以當我把資料庫欄位從屬性int改為bigint,又或者把int的長度變更就可以解決。
BIGINT
從-2^63 (-9223372036854775808) 到2^63-1 (9223372036854775807) 的整型數據(所有數字)。存儲大小為8 個字節。
INT
從-2^31 (-2,147,483,648)到2^31 – 1 (2,147,483,647)的整型數據(所有數字)。存儲大小為4個字節。

以上紀錄~

#php  #PDO  #Mysql  #錯誤訊息  #IPV6  #bigint  #int  #500  
https://innstory.com/story-PDO_PHP__PDOException__Numeric_value_out_of_range_1264_Out_of_range_value_for_column_userip_at_row_1-2566
Mysql

Prev
 htaccess與RewriteEngine一起使用時500內部服務器錯誤

Next
在PHP中如何將NAN轉換為0 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

刪除已上傳至server的檔案

刪除已上傳至server的檔...

a5 管理系統,難免都會遇到要更新或刪除已經上傳到server的檔案。 總不能只是重新上傳卻又不把舊...

Linux下查詢已安裝的PHP版本

Linux下查詢已安裝的PH...

紀錄PHP在Linux底下版本查詢方式 以Ubuntu為例 root@ubuntu:~# php –...

PHP 字串字數計算並隱藏

PHP 字串字數計算並隱藏

fontphoto55 使用PHP substr函式可以做字串切割,但在遇到中文字時記得使用mbsu...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format