如果包含特定字段,WHERE子句将不起作用

时间:2019-06-07 07:23:49

标签: php mysql mysqli where-clause

我有一个简单的SQL查询,如果我包含ID字段,则根本无法使用。 说明:如果我删除对ID的引用,不更改max_connections或其他任何内容,则代码将运行。

如果我说WHERE CustomerProfile.ID or SponsorID,则不起作用。

如果我自己说CustomerProfile.ID,那是行不通的。

仅当我说SponsorID时才有效。

IDSponsorID字段均为INT(11)IDAutoIncrement。两者都将Null设置为NoSponsorID默认为0

代码:-

<?php
function fdownline($selectedcustomerid){
    if (empty($selectedcustomerid)){
        exit;
    }
    include ('incconn.php');//this only contains database, host, user and password
    mysqli_close($dbconnection); 
    $dbconnection = mysqli_connect($dbhost,$dbusername,$dbpassword,$database) or die (mysqli_error());
    global $biglist;    
    $myquery = "SELECT * FROM CustomerProfile WHERE CustomerProfile.SponsorID = $selectedcustomerid";// this works
    //$myquery = "SELECT * FROM CustomerProfile WHERE CustomerProfile.ID = $selectedcustomerid OR CustomerProfile.SponsorID = $selectedcustomerid";//Does not work
    //$myquery = "SELECT * FROM CustomerProfile WHERE CustomerProfile.ID = $selectedcustomerid";//Does not work
    $result = mysqli_query($dbconnection, $myquery) or die (mysqli_error($dbconnection));
    if (mysqli_num_rows($result)>0){
        while ($myrow = mysqli_fetch_array($result)){
            $customerid = $myrow['ID'];
            $biglist[$customerid] = $myrow;
            fdownline($customerid); 
        }   
    }
// close connection
mysqli_close($dbconnection);    
}
?>

结果页面来源错误:

  

mysqli_connect()[function.mysqli-connect]:   (08004/1040):连接过多

0 个答案:

没有答案