Automatically clip strings to the proper length on insert

前端 未结 3 714
你的背包
你的背包 2021-01-15 16:35

I have a table with various VARCHAR fields in MySQL. I would like to insert some user data from a form via PHP. Obviously if I know the field lengths in PHP, I can limit the

3条回答
  •  Happy的楠姐
    2021-01-15 17:16

    you could query information_schema to get the lenght of the column and use that data to truncate before insert, but that's more overhead than necessary. just turn off strict SQL mode for this statement:

    SET @prev_mode = @@sql_mode;
    SET sql_mode = '';
    INSERT blah....;
    SET sql_mode = @prev_mode;
    

提交回复
热议问题