<tfoot id='aM97x'></tfoot>

    <small id='aM97x'></small><noframes id='aM97x'>

  1. <legend id='aM97x'><style id='aM97x'><dir id='aM97x'><q id='aM97x'></q></dir></style></legend>

    1. <i id='aM97x'><tr id='aM97x'><dt id='aM97x'><q id='aM97x'><span id='aM97x'><b id='aM97x'><form id='aM97x'><ins id='aM97x'></ins><ul id='aM97x'></ul><sub id='aM97x'></sub></form><legend id='aM97x'></legend><bdo id='aM97x'><pre id='aM97x'><center id='aM97x'></center></pre></bdo></b><th id='aM97x'></th></span></q></dt></tr></i><div id='aM97x'><tfoot id='aM97x'></tfoot><dl id='aM97x'><fieldset id='aM97x'></fieldset></dl></div>
        <bdo id='aM97x'></bdo><ul id='aM97x'></ul>
    2. PDO bind_param 是未定义的方法

      时间:2023-10-05
      <i id='ttwa0'><tr id='ttwa0'><dt id='ttwa0'><q id='ttwa0'><span id='ttwa0'><b id='ttwa0'><form id='ttwa0'><ins id='ttwa0'></ins><ul id='ttwa0'></ul><sub id='ttwa0'></sub></form><legend id='ttwa0'></legend><bdo id='ttwa0'><pre id='ttwa0'><center id='ttwa0'></center></pre></bdo></b><th id='ttwa0'></th></span></q></dt></tr></i><div id='ttwa0'><tfoot id='ttwa0'></tfoot><dl id='ttwa0'><fieldset id='ttwa0'></fieldset></dl></div>

            <tbody id='ttwa0'></tbody>

          <small id='ttwa0'></small><noframes id='ttwa0'>

            <tfoot id='ttwa0'></tfoot>

              • <bdo id='ttwa0'></bdo><ul id='ttwa0'></ul>
                <legend id='ttwa0'><style id='ttwa0'><dir id='ttwa0'><q id='ttwa0'></q></dir></style></legend>
                本文介绍了PDO bind_param 是未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在远离 mysql 和 mysqli,因为 stackoverflow 上的许多用户一直在说好话.

                I'm moving away from mysql and mysqli as many users on stackoverflow are constantly saying good things about it.

                我制作了一个数据库类并对此进行了测试,这可以很好地连接到数据库.我试图更新我准备好的语句以匹配但是我在陌生的领域并最终收到以下错误:

                I've made a database class and have tested this, this connects fine to the database. I've tried to update my prepared statements to match however I am in unfamiliar territory and have ended up getting the following error:

                Fatal error: Call to undefined method PDOStatement::bind_param() in E:xampphtdocsimanageinsert.php on line 50

                这反映了这一行:

                $stmt->bind_param("s", $_POST['email']);

                另外,关于这个,我得到了数据库连接成功和关闭语句返回给我以及致命错误,例如:

                Also in regards to this I am getting the database connection success and close statements returned to me as well as the fatal error e.g:

                连接数据库成功!连接数据库成功!断开数据库连接成功!

                我将解释我想要实现的目标:

                I'll explain what I am trying to achieve:

                • 在注册用户之前检查数据库中是否存在电子邮件
                • 如果是,请告诉用户此电子邮件存在
                • 如果不匹配,则将用户插入到用户表中并加密密码

                相关代码如下,如果有人能给我一些指导,我将不胜感激.

                The relevant code is below and would appreciate if anyone could give me some guidance on this.

                index.php

                        <form id="loginForm" method="POST" action="class.Login.php">
                        <input type="text" id="email" name="email" placeholder="E-mail">
                        <input type="password" id="password" name="password" placeholder="Password" class="showpassword"> 
                        <input type="submit" name="submit" value="Log in"></form>
                

                插入.php

                public function insert() {
                
                                    $stmt = $this->pdo->prepare("SELECT COUNT(*) FROM users WHERE email=?");
                                    $stmt->bind_param("s", $_POST['email']);
                                    $stmt->execute();
                                    $stmt->bind_result($email_count);
                                    $stmt->fetch();//fecth
                                    $stmt->close();     
                
                                    if ($email_count > 0) {
                                        echo "email exisits! click here to try <a href='register'>again</a>";
                                        } else {
                                            //escape the POST data for added protection
                                            $username = isset($_POST['username']) ? $_POST['username'] : null;
                                            $cryptedPassword = crypt($_POST['password']);
                                            $password = $cryptedPassword;
                                            $name = isset($_POST['name']) ? $_POST['name'] : null;
                                            $email = isset($_POST['email']) ? $_POST['email'] : null;
                                            $stmta = $this->pdo->prepare("INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, ?)");
                                            //var_dump($this->pdo->error);
                                            $stmta->bind_param('ssss', $username, $password, $name, $email); // bind strings to the paramater
                
                                                /* execute prepared statement */
                                                $stmta->execute();
                                                printf("%d Row inserted.
                ", $stmta->affected_rows);
                                                /* close statement and connection */
                                                $stmta->close();
                                } // end email_count and insert to table
                            } // end function
                

                connect/class.Database.php

                connect/class.Database.php

                <?php
                
                // Database connection PDO
                
                class Database {
                
                    public function __construct() {
                        // Connection information
                        $host   = 'localhost';
                        $dbname = 'imanage';
                        $user   = 'root';
                        $pass   = '';
                
                        // Attempt DB connection
                        try
                        {
                            $this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
                            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                            echo 'Successfully connected to the database!';
                        }
                        catch(PDOException $e)
                        {
                            echo $e->getMessage();
                        }
                
                    }
                
                     public function __destruct()
                    {
                        // Disconnect from DB
                        $this->pdo = null;
                        echo 'Successfully disconnected from the database!';
                    }
                
                
                }
                
                $run = new Database();
                ?>
                

                推荐答案

                一些 PDO 示例

                绑定参数示例

                $stmt = $this->pdo->prepare("SELECT COUNT(*) FROM users WHERE email=:email");
                $stmt->bindParam(":email", $_POST['email']);
                $stmt->execute();
                $stmt->fetch(PDO::FETCH_ASSOC);
                

                数组示例

                $data = array($username, $password, $name, $email); 
                $stmta = $this->pdo->prepare("INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, ?)");
                $stmta->execute($data);
                

                PDO教程

                这篇关于PDO bind_param 是未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 PDO MySQL 插入 2 个表 下一篇:相当于 mysql_num_rows 或 mssql_num_rows 的 PDO

                相关文章

                最新文章

                1. <tfoot id='OL0ay'></tfoot>

                  1. <legend id='OL0ay'><style id='OL0ay'><dir id='OL0ay'><q id='OL0ay'></q></dir></style></legend>
                    • <bdo id='OL0ay'></bdo><ul id='OL0ay'></ul>
                  2. <small id='OL0ay'></small><noframes id='OL0ay'>

                    <i id='OL0ay'><tr id='OL0ay'><dt id='OL0ay'><q id='OL0ay'><span id='OL0ay'><b id='OL0ay'><form id='OL0ay'><ins id='OL0ay'></ins><ul id='OL0ay'></ul><sub id='OL0ay'></sub></form><legend id='OL0ay'></legend><bdo id='OL0ay'><pre id='OL0ay'><center id='OL0ay'></center></pre></bdo></b><th id='OL0ay'></th></span></q></dt></tr></i><div id='OL0ay'><tfoot id='OL0ay'></tfoot><dl id='OL0ay'><fieldset id='OL0ay'></fieldset></dl></div>