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

  • SEARCH
  • Home
  • 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 6796083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:25:28+00:00 2026-05-26T18:25:28+00:00

I have a VARCHAR(4) column that receives data from an input that may be

  • 0

I have a VARCHAR(4) column that receives data from an input that may be above 4 characters. This is okay, though, and I let MySQL naturally (or so I thought) cut off the end of the characters.

Strangely enough, when I’m looking at the database row results later in PHP (Using the PDO driver), the entire string is displaying, not just the 4 characters.

Weird thing is, if I do a SELECT query on the MySQL CLI, it only returns the 4 characters. Even when I do a mysqldump, only the 4 characters show.

Any idea what could cause this odd inconsistency?

Note that these characters are all numbers.

Edit: By request, here’s some psuedocode that represents the save/fetch methods:

Storing:

$data = array(
     'name_first4'       => $fields['num'],   
     // name_first4 is the column name with VARCHAR(4)
);
$where = $this->getTable()->getAdapter()->quoteInto('id = ?', $id);
$this->getTable()->update($data,$where);

Fetching, using Zend_Db_Table:

$row = $this->getTable()->fetchRow(
    $this->getTable()->select()->where('id=?',$data)
);
  • 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-05-26T18:25:29+00:00Added an answer on May 26, 2026 at 6:25 pm

    If you’re doing this:

    1. Create or load an object $o.
    2. Assign '12345' to the property/column in question.
    3. Save $o and let MySQL truncate the value to '1234'.
    4. Access the property/column in $o and get '12345' back.

    then you’re seeing one of the problems of letting your database silently mangle your data.

    The save succeeds, your object has no idea that MySQL has truncated the data so it keeps the '12345' around rather than reloading that column from the database, and you have inconsistent data on your hands.

    If you’re depending on MySQL silently truncating your data then you’ll probably have to do this:

    1. Create/load your object.
    2. Updated the properties.
    3. Save the object.
    4. Throw away your local reference to the object.
    5. Load it fresh from the database to make sure you get the real values.

    I’d recommend adding strict validations to your objects to avoid the silent truncation inside MySQL. Turning on strict mode would also avoid this problem but then you’d need to review and tighten up all your error handling and data validation (which wouldn’t really be a bad thing).

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

Sidebar

Related Questions

I have a varchar column that has data like this top<somenumber> so the word
I have SQL table that has a varchar(8) column that occasionally has binary data
I have some data which is stored in a VARCHAR(MAX) column that contains the
Let's say I have a column of varchar(40) with data already and i change
I have a column varchar[25] with this data inside : 886,-886 -886 0,-1234 1234
I have a VARCHAR column in a SQL Server 2000 database that can contain
I have a varchar(100) column in a table that contains a mix of integers
I have column with varchar values like 022008 that I need to convert into
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I have a column in my SQL-2005 database that used to be a varchar(max)

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.