echo_loser Posted January 26, 2012 Share Posted January 26, 2012 If say, you were to set a table field to VARCHAR(5), and the user were to enter a string that is 6 characters long, how would MySQL react? Would it store the first 5 characters and ignore the last 6th character? In the case that there is NO server side checking of course. I did keyword searches on Google with no luck to my question being answered. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2012 Share Posted January 26, 2012 This is something you can easily test yourself. Quote Link to comment Share on other sites More sharing options...
floridaflatlander Posted January 26, 2012 Share Posted January 26, 2012 Would it store the first 5 characters and ignore the last 6th character? Yes Quote Link to comment Share on other sites More sharing options...
DavidAM Posted January 26, 2012 Share Posted January 26, 2012 There is a setting in the mySQL configuration file that affect this. It will either truncate to the defined (maximum) length and issue a warning; OR it will raise an error (and not insert the data at all). See the mySql manual If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode. See Section 5.1.6, “Server SQL Modes”. [EDIT] It is good to be aware of these things, since the setting may be different between your development platform and the production server; which could cause errors to start occurring when moving from one server to the other. [/EDIT] Quote Link to comment Share on other sites More sharing options...
echo_loser Posted January 27, 2012 Author Share Posted January 27, 2012 This is something you can easily test yourself. Yeah, you're right. I won't waste the time of this forum with questions like these in the future. Sorry about that... just a bit new to the whole PHP thing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.