Imran
Imran

Reputation: 3072

mysql column datatype issue for wrong input

Sometime,may be unnecessary behavior in column datatype.

If I insert more than 4 digits data in TINYINT column it insert 255 with out of range warning.

If I want UPDATE or INSERT string value in FLOAT column it makes 0.

But when I try to change negative number in unsigned datatype, query is not being execute.

My question is why not stop querying when doesn't match datatype all time . have any idea to stop querying for this type situations?

Upvotes: 0

Views: 760

Answers (1)

weia design
weia design

Reputation: 1310

To do that, you need to manually add error check with the program language you are using. Since once the data going to the database, it is "queried"

Example way to do error check with PHP:

    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");

    /* check connection */
    if ($mysqli->connect_errno) {
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit();
    }

    if (!$mysqli->query("SET a=1")) {
        printf("Errormessage: %s\n", $mysqli->error);
    }

    /* close connection */
    $mysqli->close();
    ?>

hope it helps :)

Upvotes: 1

Related Questions