복붙노트

Mysqli_Query 경고 : mysqli_query ()는 매개 변수 1이 mysqli [duplicate]가 될 것으로 기대합니다.

PHP

Mysqli_Query 경고 : mysqli_query ()는 매개 변수 1이 mysqli [duplicate]가 될 것으로 기대합니다.

내 코드에서이 오류가있어 그것을 해결하는 방법을 모르겠다. 내 코드 :

<?php
session_start();
include_once"connect_to_mysql.php";

$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "root"; 
// Place the password for the MySQL database here
$db_pass = "****"; 
// Place the name for the MySQL database here
$db_name = "mrmagicadam";

// Run the actual connection here 
$myConnection= mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("mrmagicadam") or die ("no database");        
$sqlCommand="SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query=mysqli_query($myConnection, $sqlCommand) or die(mysql_error());
$menuDisplay="";


while($row=mysql_fetch_array($query)) {
    $pid=$row["id"];
    $linklabel=$row["linklabel"];
$menuDisplay='<a href="index.php?pid=' .$pid . '">' .$linklabel. '</a><br/>';
}
mysqli_free_result($query);

?>

이것은 오류입니다.

도와 줄수있으세요

해결법

  1. ==============================

    1.mysqli와 mysql 확장을 혼합하고있다.

    mysqli와 mysql 확장을 혼합하고있다.

    너는 다음을 사용해야한다.

    $myConnection= mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); 
    
    mysqli_select_db($myConnection, "mrmagicadam") or die ("no database");   
    

    mysqli는 원래의 mysql 확장보다 많은 개선점을 가지고 있으므로 mysqli를 사용하는 것이 좋다.

  2. ==============================

    2.부적절한 구문을 사용하고 있습니다. mysqli_query () 문서를 읽으면 두 개의 매개 변수가 필요하다는 것을 알게 될 것이다.

    부적절한 구문을 사용하고 있습니다. mysqli_query () 문서를 읽으면 두 개의 매개 변수가 필요하다는 것을 알게 될 것이다.

    mysql $ link는 일반적으로 mysqli 연결의 리소스 객체를 의미한다.

    따라서이 문제를 해결하는 두 가지 방법이 있습니다.

    mysql_query () 사용하기

    $myConnection= mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
    mysql_select_db("mrmagicadam") or die ("no database");        
    $sqlCommand="SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
    $query=mysql_query($sqlCommand) or die(mysql_error());
    

    또는 mysqli_query ();

    $myConnection= mysqli_connect("$db_host","$db_username","$db_pass", "mrmagicadam") or die ("could not connect to mysql"); 
    $sqlCommand="SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
    $query=mysqli_query($myConnection, $sqlCommand) or die(mysqli_error($myConnection));
    
  3. from https://stackoverflow.com/questions/10160664/mysqli-query-warning-mysqli-query-expects-parameter-1-to-be-mysqli by cc-by-sa and MIT license