警告:mysqli_query()需要至少2个参数,1在D:\ wamp64 \ www \ magento \ includes \ functions.php中给出第1579行

时间:2016-10-08 05:49:18

标签: php function templates

我需要再帮一点......我得到错误的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; 
    }

2 个答案:

答案 0 :(得分: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); 

答案 1 :(得分:1)

您应该参考这个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中使用它