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 7601665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:13:13+00:00 2026-05-30T23:13:13+00:00

Just wondering, if is there any class, function or ideia on how to validate

  • 0

Just wondering, if is there any class, function or ideia on how to validate a specific value/variable against a mysql data type.

We’ve got in PHP the is_int() is_string() is_float() etc etc… But we do not have them all. Or do we? Any Cheat sheet? Any thoughts?

EDIT:
The point basically is:

  • Go trought a array of values (comming from a CSV for instance).
  • I know what table, and have all the column information (data type s well) (with adodb).
  • Just check if each value fits in a specific column…
  • 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-30T23:13:14+00:00Added an answer on May 30, 2026 at 11:13 pm

    If the data is coming from a CSV file, you have to remember that all the values are going to be strings (even numeric strings still have a string type).

    So you can’t use is_int()/is_float()/etc., because that only tells you about the type or the variable. You could use is_numeric() to check the value, but this will allow for things like exponential notation like “+0123.45e6”. Sometimes ctype_digit() can be useful for testing integers for this reason, since it will only allow the numbers 0-9 to be present in a string for it to return true.

    Regular expressions can also be used to identify pattern-based data types, but you do have to watch for performance overhead when dealing with large data sets. It’s almost always advisable from a performance perspective to use the preg_ family of functions instead of the ereg functions.

    If you’re validating things like ENUM or SET types, you’ll probably need to make an array containing legal values (or extract these with a query) and then check the value against them with in_array().

    For CHAR/VARCHAR fields, you could parse the column definition and then check whether the length of the value falls within the constraints.

    If the NULL type is allowed on any of your columns, you’d also need to check against this (and probably map empty values or the string “NULL” to an actual NULL value).

    If you’re looking to actually escape these values properly, look into using prepared statements and the PDO (PHP Data Objects) extension. This allows MySQL to properly escape the data based on type. (You can also use prepared statements with MySQLi.)

    If you’re looking for specific data types and how to identify them, then you might want to edit your question to facilitate more complete answers.

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

Sidebar

Related Questions

Hey, I'm just wondering if there's any easy function to make text suitable to
I'm just wondering if there are any Java class editors that work on a
Just wondering if there is any way (in C) to get the contents of
Just wondering if there is any way to get the NS records in C#.
Just wondering if there are any pitfalls using .net as the extension for a
Just wondering if there is any benchmark software that I can download that will
Was just wondering if there are any built in functions in c++ OR c#
Was just wondering if there was any software out there to do this? The
I was just wondering if there is any difference between the two different new
I was just wondering if there are any methods of creating nice, smooth transition

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.