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. Link to comment https://forums.phpfreaks.com/topic/255804-more-characters-than-specified-in-varchar/ 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. Link to comment https://forums.phpfreaks.com/topic/255804-more-characters-than-specified-in-varchar/#findComment-1311366 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 Link to comment https://forums.phpfreaks.com/topic/255804-more-characters-than-specified-in-varchar/#findComment-1311370 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] Link to comment https://forums.phpfreaks.com/topic/255804-more-characters-than-specified-in-varchar/#findComment-1311417 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. Link to comment https://forums.phpfreaks.com/topic/255804-more-characters-than-specified-in-varchar/#findComment-1311555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.