简体   繁体   English

另一个mysqli_query()期望参数1为mysqli,给定字符串

[英]Another mysqli_query() expects parameter 1 to be mysqli, string given

i have read all the reference about this topic and follow as instruction. 我已经阅读了有关该主题的所有参考资料,并按照指示进行操作。 My other application using this step is running smoothly, but this simple query in part of my program keep showing this error : 我使用该步骤的其他应用程序运行平稳,但是在程序的一部分中,此简单查询始终显示此错误:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\\xampp183-5\\htdocs\\Development\\Pajak-Penjualan_Auto_2-0.php on line 258 警告:mysqli_query()期望参数1为mysqli,第258行的D:\\ xampp183-5 \\ htdocs \\ Development \\ Pajak-Penjualan_Auto_2-0.php中给出的字符串

Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\\xampp183-5\\htdocs\\Development\\Pajak-Penjualan_Auto_2-0.php on line 258 警告:mysqli_error()期望恰好有1个参数,第258行的D:\\ xampp183-5 \\ htdocs \\ Development \\ Pajak-Penjualan_Auto_2-0.php中给出的参数为0

Query Ref Penjualan Failed

Here the code : 这里的代码

$link = mysqli_connect('localhost', 'Username', 'Password', $_SESSION['Database']);
if (!$link) {
   die('Not connected : ' . mysqli_error());
}

$db_selected = mysqli_select_db($link, $_SESSION['Database']);
if (!$db_selected) {
  die ('Can\'t use foo : ' . mysqli_error());
}    

.
.
.//Some SqlCommand
$com = "
select h.Kode_FP, Tanggal, Ceil(
(
    SUM((Qty * Harga_Satuan)) - Potongan - Uang_Muka
)
) as Total, h.Staff, h.NPWP, h.Nama, k.Nama_Karyawan
from fp_penjualan_h h
LEFT JOIN fp_penjualan_d d ON h.Kode_FP = d.Kode_FP
LEFT JOIN karyawan k ON k.Kd_Karyawan = h.Staff
where Tanggal Between '".@$_REQUEST['Mulai']."' and '".@$_REQUEST['Sampai']."'
group by Tanggal, h.Kode_FP
".@$_REQUEST['Sort']."
";
$query = mysqli_query($link, $com) or die(mysqli_error($link)."Query Failed");
while($hasil = mysqli_fetch_array($query))
{
     $comRefPenjualan = "
     select COUNT(DISTINCT(rj.Kd_Penjualan)) as Ref_Jual
     from fp_ref_jual rj
     where rj.Kode_FP = '".$hasil[0]."'
     group by rj.Kode_FP
     ";
     $queryRefPenjualan = mysqli_query($link, $comRefPenjualan) or die(mysqli_error()."Query Ref Penjualan Failed");
     $hasilRefPenjualan = mysqli_fetch_array($queryRefPenjualan);
.
.
.

But whenever i query manual, there's no error, the query went success. 但是只要我查询手册,就不会出错,查询就会成功。 What's wrong with my code ? 我的代码有什么问题? Anyone help me please. 任何人都可以帮助我。

Instead of mysqli_error() it should be mysqli_error($link) 代替mysqli_error(),它应该是mysqli_error($ link)

mysqli_error() needs to pass the connection parameter to the database. mysqli_error()需要将连接参数传递给数据库。

To make your code better replace 为了使您的代码更好地替换

if (!$link) {
   die('Not connected : ' . mysqli_error());
}

$db_selected = mysqli_select_db($link, $_SESSION['Database']);
if (!$db_selected) {
  die ('Can\'t use foo : ' . mysqli_error());
}

To

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

As your db is already selected in $link above 由于您的数据库已在上面的$ link中选中

Also change 也改变

$query = mysqli_query($link, $com) or die(mysqli_error($link)."Query Failed");

To

if (!mysqli_query($link, $com)) {
    printf("Query Failed: %s\n", mysqli_error($link));
}else{
   $query = mysqli_query($link, $com); 
}

And this 和这个

 $queryRefPenjualan = mysqli_query($link, $comRefPenjualan) or die(mysqli_error()."Query Ref Penjualan Failed");

TO

if (!mysqli_query($link, $comRefPenjualan)) {
    printf("Query Ref Penjualan Failed: %s\n", mysqli_error($link));
} else {
   $queryRefPenjualan = mysqli_query($link, $comRefPenjualan); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM