Jump to content

Inserting the wrong number in a column of specific numeric type..


lordvader

Recommended Posts

Okay, I got a tinyint unsigned column, which means the highest number you could put in there is 255.

 

Is there a 'mode' that would throw an error on the screen if your php tries to insert a value higher than 255?

 

This thing that I'm writing has a counter which I don't want to able to run up indefinitely. It's not difficult to include the extra code to manually limit the count, but I don't want to if I don't have to, since there is already a built-in sort of limiter by using specific numeric types.

 

I plan on giving my code to a lot of people for their sites, so it'll be too hard to find out what mysql mode everybody's host is set on.

 

thanks

 

 

Link to comment
Share on other sites

In my opinion the best way when it comes to checking allowed values of database fields is to use DESCRIBE information before saving data. That lets you do not worry about correctness of data ranges even if your interface validation fails. Additionally when you will need to change values ranges you just alter database structure and your application will follow these changes.

Link to comment
Share on other sites

My concern is whether or not there is a setting that will halt all rendering and output a mysql error message to the visitor. Because if that's a possiblity, then I'll have to include the code to manually limit the counter from incrementing if it's at 255 already.

 

 

Link to comment
Share on other sites

My concern is whether or not there is a setting that will halt all rendering and output a mysql error message to the visitor. Because if that's a possiblity, then I'll have to include the code to manually limit the counter from incrementing if it's at 255 already.

Rendering isn't mysql.  You can decide how you want mysql to behave at this stage -- throw an error or not -- but it's up to you (your code) how to handle this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.