Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9042105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:24:13+00:00 2026-06-16T10:24:13+00:00

My MySQL Server (running with PHP via PDO on Windows 2008 Server) returns error

  • 0

My MySQL Server (running with PHP via PDO on Windows 2008 Server) returns error code 1406 (data too long for field) when inserting strings longer than allowed in a column. The thing is I read somewhere that what MySQL usually truncates the data when it is not in strict mode. I changed the sql_mode in my.ini so that even at startup it doesn’t enter in strict mode (it is currently “”), but it is still giving me the error and rolls back, so the data is lost (truncating is the desired behaviour of the site).

I entered to the command line and made an insert with a long string in a shorter varchar field and it does truncate the data and save, but it is the site that doesn’t. When I changed the mode back to strict, it didn’t truncate in the command line (only the error).

Also, I made the site output the current sql mode, both global and session (@@GLOBAL.sql_mode and @@SESSION.sql_mode) and they both output “” but just don’t work as desired.

Does anyone know what is causing this and/or how to change it?

My suspicion is that it may have to do with PDO enabled with PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION, but I have read and can’t find anything helpful about that (I don’t really think this is definitely the explanation, but I am just putting this out there so that you know as much as possible about the problem).

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:24:14+00:00Added an answer on June 16, 2026 at 10:24 am

    You should not really do that – please don’t let bad data into your database, and sanitize it in your scripts before you insert.

    If you don’t know actual width of your VARCHAR columns or don’t want to hard-code it in your scripts, you can read it from database by querying INFORMATION_SCHEMA table COLUMNS using query like this:

    SELECT
        column_name,
        data_type,
        character_maximum_length,
        ordinal_position
    FROM information_schema.columns
    WHERE table_name = 'mytable'
    

    (you may want to limit this to only data_type = 'varchar').
    Having this information and specifically character_maximum_length, you can use PHP substr to trim your input strings to desired length.

    Advantage of this approach is that it does not alter any server configuration, and should work for any other databases, not only MySQL.

    But if you insist on doing it unsafe way, you can try to temporarily disable strict mode by executing this:

    SET sql_mode = '';
    

    After that MySQL should silently trim strings. Read more here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is running on Windows Server 2008 R2 MySQL (phpmyadmin) shows Server: localhost via
I send data from Android via HTTP Post to a Server running PHP and
I am running an Apache/PHP/MySQL server (xampp) on my local machine under Windows 7.
I have had apache, php, and mysql server 5.5 installed locally and happily running
My php code fails to connect to the mysql database on my web server.
I am trying to retrieve data from MySQL for a flash application via PHP,
I have a PHP/MySQL application running with WAMP on a local server. This application
i have installed xampp on my windows server 2008 R2. I'm running a script
I'm not able connect to mysql via php. It produces [error] [client 127.0.0.1] PHP
I have an OS X 10.6 Server running, which has PHP, Apache, MySQL, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.