微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐