• <bdo id='oQjif'></bdo><ul id='oQjif'></ul>
    <tfoot id='oQjif'></tfoot>

      <legend id='oQjif'><style id='oQjif'><dir id='oQjif'><q id='oQjif'></q></dir></style></legend>

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

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

        如何从 mysql_* 升级到 mysqli_*?

        时间:2023-07-29

      2. <small id='EstiN'></small><noframes id='EstiN'>

          <tbody id='EstiN'></tbody>
                <legend id='EstiN'><style id='EstiN'><dir id='EstiN'><q id='EstiN'></q></dir></style></legend>
                <i id='EstiN'><tr id='EstiN'><dt id='EstiN'><q id='EstiN'><span id='EstiN'><b id='EstiN'><form id='EstiN'><ins id='EstiN'></ins><ul id='EstiN'></ul><sub id='EstiN'></sub></form><legend id='EstiN'></legend><bdo id='EstiN'><pre id='EstiN'><center id='EstiN'></center></pre></bdo></b><th id='EstiN'></th></span></q></dt></tr></i><div id='EstiN'><tfoot id='EstiN'></tfoot><dl id='EstiN'><fieldset id='EstiN'></fieldset></dl></div>
                  <bdo id='EstiN'></bdo><ul id='EstiN'></ul>
                • <tfoot id='EstiN'></tfoot>
                  本文介绍了如何从 mysql_* 升级到 mysqli_*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前使用已弃用的代码从用户那里获取数据,如下所示:

                  I'm currently using deprecated code to get data from users, as follows:

                  /* retrieve */
                  $lastName = $_POST['lastName']; 
                  $firstName = $_POST['firstName']; 
                  $examLevel=$_POST['level'];
                  
                  /* connect */
                  $dbc=mysql_connect("localhost", "user", "passw") or die('Error connecting to MySQL server');
                  mysql_select_db("db") or die('Error selecting database.');
                  
                  /* sanitize */
                  $lastName=mysql_real_escape_string($lastName);
                  $firstName=mysql_real_escape_string($firstName); 
                  $examLevel=mysql_real_escape_string($examLevel);
                  
                  
                  /* insert */
                  $query_personal = "INSERT INTO personal (LastName, FirstName) VALUES  ('$lastName', '$firstName')";
                  
                  $query_exam = "INSERT INTO exam (Level, Centre, BackupCentre, etc.) VALUES ('$examLevel', '$centre', '$backup', 'etc')";
                  

                  这是有效的,但我不断收到有关安全性和缺乏支持的警告.使用 mysqli 而不是 mysql connect 有一个小的重写,但是 mysqli_real_escape_string 怎么样?我已经在示例中看到了它,但我也看到了使用准备好的语句而不是不使用 mysqli_real_escape_string 的建议.

                  This is working but I keep coming across warnings about security and lack of support. There's a small rewrite to connect with mysqli instead of mysql but what about mysqli_real_escape_string? I've seen it used in examples but I've also seen advice to use prepared statements instead which don't use mysqli_real_escape_string.

                  我将如何使用准备好的语句来插入我的数据?到目前为止,我对此有点茫然.比如参数绑定只针对INSERT,结果绑定只针对SELECT?

                  And how would I use prepared statements to INSERT my data? I'm a bit at sea with this bit so far. For example, is parameter binding only for INSERTs and result binding only for SELECTs?

                  推荐答案

                  将其转换为 PDO

                  /* connect */
                  $dsn = "mysql:host=localhost;db=test;charset=utf8";
                  $opt = array(
                      PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                      PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
                  );
                  $pdo = new PDO($dsn,"user", "passw", $opt);
                  
                  
                  /* insert */
                  $query = "INSERT INTO personal (LastName, FirstName) VALUES  (?, ?)";
                  $stmt  = $pdo->prepare($query);
                  $stmt->execute(array($_POST['lastName'],$_POST['firstName']));
                  
                  $query = "INSERT INTO exam (Level, Centre, BackupCentre, etc) VALUES (?, ?, ?, 'etc')";
                  $stmt  = $pdo->prepare($query);
                  $stmt->execute(array($_POST['level'], $centre, $backup));
                  

                  这篇关于如何从 mysql_* 升级到 mysqli_*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:“加载数据本地 infile"不允许命令 下一篇:在 MySQLi 上使用 bind_param() 时是否需要转义数据以

                  相关文章

                  最新文章

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

                    <legend id='AVDpX'><style id='AVDpX'><dir id='AVDpX'><q id='AVDpX'></q></dir></style></legend>
                      <bdo id='AVDpX'></bdo><ul id='AVDpX'></ul>

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

                    2. <small id='AVDpX'></small><noframes id='AVDpX'>