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

<small id='6W2ED'></small><noframes id='6W2ED'>

        mysqli_prepare() 期望参数 1 是 mysqli

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

          <tfoot id='ulofi'></tfoot>

            <tbody id='ulofi'></tbody>

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

                • <small id='ulofi'></small><noframes id='ulofi'>

                  本文介绍了mysqli_prepare() 期望参数 1 是 mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在使用 mysqli

                  功能如下:

                  db.php

                  <?php
                  define("DB_HOST", "host");
                  define("DB_LOGIN", "login");
                  define("DB_PASSWORD", "password");
                  define("DB_NAME", "myDb");
                  
                  $link = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
                  if(!$link) {
                      echo 'ERROR: ' . mysqli_connect_errno() . ': ' . mysqli_connect_error();
                  }
                  ?>
                  

                  function.php

                  <?php
                  function addItemToCatalog($var1, $var2, $var3, $var4) {
                      $sql = 'INSERT INTO catalog (var1, var2, var3, var4) 
                              VALUES (?, ?, ?, ?)';
                      if (!$stmt = mysqli_prepare($link, $sql)){
                          return false;
                      }
                      mysqli_stmt_bind_param($stmt, "ssii", $var1, $var2, $var3, $var4);
                      mysqli_stmt_execute($stmt); 
                      mysqli_stmt_close($stmt); 
                      return true;
                  }
                  ?>
                  

                  page.php

                  <?php
                  require_once ("db.php");
                  require_once ("function.php");
                  
                  $var1 = $_POST['var1']; //showing without filtering methods
                  $var2 = $_POST['var2'];
                  $var3 = $_POST['var3'];
                  $var4 = $_POST['var4'];
                  
                  if(!addItemToCatalog($var1, $var2, $var3, $var4)){ 
                      echo 'some error text';
                  }
                  else { 
                      header("Location: success.php"); 
                      exit;
                  }
                  ?>
                  

                  使用后有

                  警告:mysqli_prepare() 期望参数 1 为 mysqli,第 5 行 function.php 中给出的 null.

                  WARNING: mysqli_prepare() expects parameter 1 to be mysqli, null given in function.php on line 5.

                  有人吗?

                  推荐答案

                  两个文件 db.phpfunction.php 粘在一起的方式我认为导致$link 被定义为全局变量 - 您需要使用 global 在函数内访问它:

                  The way the two files db.php and function.php are glued together I think results in $link being defined as a global variable - you need to use global to access it within function:

                  function addItemToCatalog($var1, $var2, $var3, $var4) {
                      global $link;
                      ...
                  }
                  

                  或通过参数显式地将$link给函数:

                  or give the $link to the function explicitly through parameter:

                  function addItemToCatalog($var1, $var2, $var3, $var4, $link) {
                      ...
                  }
                  

                  这篇关于mysqli_prepare() 期望参数 1 是 mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:未使用函数 password_verify 验证密码 下一篇:mysqli_stmt::bind_result(): 绑定变量的数量与 PHP 中准

                  相关文章

                  最新文章

                      • <bdo id='SKq3I'></bdo><ul id='SKq3I'></ul>
                    1. <small id='SKq3I'></small><noframes id='SKq3I'>

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