sql列类型从TEXT更改为varchar时无法登录php页面

当密码的列类型为TEXT时,我的登录页面过去可以正常工作.
我已经更新了表内容,并习惯了使用sql密码功能使用密码,但是现在的格式是varchar,该页面将无法进行身份验证.

下面是有问题的代码

<main>
            <?PHP 
                if(isset($_POST['submit'])){
                    include 'databaselogin.PHP';

                    $username = ucfirst(strtolower($_POST['username']));
                    $username = MysqLi_real_escape_string($MysqLi, $username);
                    $password = $_POST['password'];

                    $sql = "SELECT *
                            FROM teams
                            WHERE name = '$username'";
                    $result = $MysqLi->query($sql) or die($MysqLi->error.__LINE__);

                    if($result->num_rows == 1){
                        $row = $result->fetch_assoc();
                        $hash = $row["password"];

                        if(password_verify($password,$hash)){
                            session_start();
                            $_SESSION["username"] = $row["name"];

                            header("Location: http://www.josephade.com/fyp/dashboard.PHP");
                            die();
                        }
                    }else{
                        //Show error incorrect password
                        include 'error.PHP';
                    }

                    MysqLi_close($MysqLi);
                }
            ?>

解决方法:

正如在MysqL文档中有关BLOB和TEXT的内容一样.

> http://dev.mysql.com/doc/refman/5.6/en/blob.html

11.4.3 BLOB和TEXT类型

If strict sql mode is not enabled and you assign a value to a BLOB or TEXT 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.

这可以解释数据丢失.

>因此,如从我的评论中所述,需要从TEXT到VARCHAR进行完全重建:

“you may have to rebuild your hashes then”

我发现与此有关的另一个链接

> http://nicj.net/mysql-text-vs-varchar-performance/

从该页面部分检索:

Starting with MysqL 5.0.3, the maximum field length for VARCHAR fields was increased from 255 characters to 65,535 characters. This is good news, as VARCHAR fields, as opposed to TEXT fields, are stored in-row for the MyISAM storage engine (InnoDB has different characteristics). TEXT and BLOB fields are not stored in-row — they require a separate lookup (and a potential disk read) if their column is included in a SELECT clause. Additionally, the inclusion of a TEXT or BLOB column in any sort will force the sort to use a disk-based temporary table, as the MEMORY (HEAP) storage engine, which is used for temporary tables, requires.

Thus, the benefits of using a VARCHAR field instead of TEXT for columns between 255 and 65k characters seem obvIoUs at first glance in some scenarios: potentially less disk reads (for queries including the column, as there is no out-of-row data) and less writes (for queries with sorts including the column).

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...