【问题标题】:Warning: mysqli_query() expects at least 2 parameters, 1 given in D:\wamp64\www\magento\includes\functions.php on line 1579 [duplicate]警告:mysqli_query() 至少需要 2 个参数,1 个在 D:\wamp64\www\magento\includes\functions.php 第 1579 行 [重复]
【发布时间】:2016-10-08 05:49:17
【问题描述】:

我又需要一点帮助...我得到错误的mysql参数,我知道问题但我找不到丢失的参数...这是问题行

**`$result_template = mysqli_query($select_template) or die(mysql_error());`**

我知道缺少 1 个参数,但我不知道是哪一个??你能帮帮我吗?谢谢

这部分代码可能有用....

/*function to display the active template*/


    function displayTemplate(){
        $tableprefix = "";
        global $tableprefix,$_SESSION;
        $template_array = array();

         $select_template = "SELECT vtop_filename,vleft_filename,vbottom_filename,vimages_folder,vcss_name,vtemplate_name
                            FROM ".$tableprefix."template_master WHERE vactive_status = 'Y'";

1579---->>>>   $result_template = mysqli_query($select_template) or die(mysql_error());

        $template_row = mysql_fetch_assoc($result_template);

        array_push($template_array,$template_row['vtop_filename'],$template_row['vleft_filename'],$template_row['vbottom_filename'],$template_row['vimages_folder'],$template_row['vcss_name'],$template_row['vtemplate_name']);

    return $template_array; 
    }

【问题讨论】:

  • 你需要将连接变量传递给 mysqli 函数
  • 对不起@Kinshuk 我听不懂
  • 你错过了 Connection 对象....这里是快速语法参考 $res=mysqli_query($con_object,$query);
  • mysqli_query($conn,$select_template) 添加您的连接变量
  • 您已经在某个变量中设置了 mysqli_connect。将该变量传递给函数的第一个位置。

标签: php function templates


【解决方案1】:

你需要告诉它连接到哪里。这是从 PHP 连接到数据库的工作代码的简单示例。

 <php 

//Connect to DB 
$conn = new mysqli("Hostname","Username","Password","Database"); 

//If the connection has errors 
if ($conn->connect_error){ 
  //Display the error 
  die("Connection failed because: " . $conn->connect_error); 
} 

//Otherwise the connection is good so lets create a sql query 
$sql = "SELECT * FROM Database"; 

//Get the results of the query 
$result = $conn->query($sql); 

【讨论】:

    【解决方案2】:

    你应该参考这个here的php文档

    由于您使用的是过程样式,因此您必须将 mysqli_connect 资源传递给您的 mysqli_query

    <?php
    $link = mysqli_connect("localhost", "my_user", "my_password", "world");
    
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    /* Create table doesn't return a resultset */
    if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
        printf("Table myCity successfully created.\n");
    }
    
    /* Select queries return a resultset */
    if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
        printf("Select returned %d rows.\n", mysqli_num_rows($result));
    
        /* free result set */
        mysqli_free_result($result);
    }
    
    /* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
    if ($result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT)) {
    
        /* Note, that we can't execute any functions which interact with the
           server until result set was closed. All calls will return an
           'out of sync' error */
        if (!mysqli_query($link, "SET @a:='this will not work'")) {
            printf("Error: %s\n", mysqli_error($link));
        }
        mysqli_free_result($result);
    }
    
    mysqli_close($link);
    ?>
    

    但是我可以看到你在某个函数中使用它,所以将一个 db 对象传递给这个函数,然后在你的 mysqli_query 中使用它

    【讨论】:

      猜你喜欢
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 2020-10-01
      • 1970-01-01
      • 2011-12-25
      相关资源
      最近更新 更多