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

利用 .htaccess 限制可瀏覽ip來源

利用 .htaccess 限...

要如何限制某個資料夾內容只能給特定IP讀取? 這個部分其實可以透過.htaccess快速實現~ 首先...

使用jQuery阻止input直接按Enter就送出表單

使用jQuery阻止inpu...

使用表單是傳送資料裡經常會用到的方式。 這時當使用者輸入表單後習慣上按下Enter,則會將表單內容送...

在PHP中如何將NAN轉換為0

在PHP中如何將NAN轉換為...

首先我會得到NAN是因為我有一個計算結果為的值然後我讓他除以,結果就得到了NAN 首先甚麼是NAN?...

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