我正在努力使这个脚本工作但是向我展示了这个问题

问题描述 投票:0回答:1

警告:mysqli_query()期望参数2是字符串,对象在C:\ xampp \ htdocs中给出

/**
    * Build new customer number
    * @return varchar custNo :  Newly build customer number
    */  
    function buildCustNo(){ 
    /*Establish Database connection
    */
        $link = mysqli_connect("localhost","root","","mysaccodb") or die("Unable to Connect to Database");      


    // Determine biggest customer ID
    $sql_maxID = mysqli_query($link,"SELECT MAX(cust_id) AS maxid FROM customer") or die ("Error" . mysqli_error($link));
    $query_maxID = mysqli_query($link, $sql_maxID);
    checkSQL($query_maxID);
    $result_maxID = mysqli_fetch_array($query_maxID);

    // Read customer number format
    $cnParts = explode("%", $_SESSION['set_cno']);
    $cnCount = count($cnParts);

    // Build customer number
    $i = 0;
    $custNo = "";
    for ($i = 1; $i < $cnCount; $i++) {
        switch($cnParts[$i]){
            case "N":
                $custNo = $custNo.($result_maxID['maxid'] + 1);
                break;
            case "Y":
                $custNo = $custNo.date("Y",time());
                break;
            case "M":
                $custNo = $custNo.date("m",time());
                break;
            case "D":
                $custNo = $custNo.date("d",time());
                break;
            default:
                $custNo = $custNo.$cnParts[$i];
        }
    }

    // Return customer number
    return $custNo;
}
php mysqli
1个回答
1
投票

你在mysqli_query中使用mysqli_query,这是行不通的。看看它应该如何。

/**
* Build new customer number
* @return varchar custNo :  Newly build customer number
*/  
function buildCustNo(){ 
/*Establish Database connection
*/
    $link = mysqli_connect("localhost","root","","mysaccodb") or die("Unable to Connect to Database");      


// Determine biggest customer ID// Determine biggest customer ID
$sql_maxID = "SELECT MAX(cust_id) AS maxid FROM customer";
$query_maxID = mysqli_query($link, $sql_maxID)  or die ("Error" . mysqli_error($link));

checkSQL($query_maxID);
$result_maxID = mysqli_fetch_array($query_maxID);

// Read customer number format
$cnParts = explode("%", $_SESSION['set_cno']);
$cnCount = count($cnParts);

// Build customer number
$i = 0;
$custNo = "";
for ($i = 1; $i < $cnCount; $i++) {
    switch($cnParts[$i]){
        case "N":
            $custNo = $custNo.($result_maxID['maxid'] + 1);
            break;
        case "Y":
            $custNo = $custNo.date("Y",time());
            break;
        case "M":
            $custNo = $custNo.date("m",time());
            break;
        case "D":
            $custNo = $custNo.date("d",time());
            break;
        default:
            $custNo = $custNo.$cnParts[$i];
    }
}

// Return customer number
return $custNo;
}