nothing wrong with your function .but
SELECT MAX(strRefNo) AS refnum FROM claims
WHERE strRefNo LIKE ''".$year."'%';
parameter binding doing in the wrong way ''".$year."'%'
should be changed as '".$year."%'
.
Change function
function create_referance_key($connect, $empno){
/**********************create referance key********************************/
$year = date('Y');;
$query = "
SELECT MAX(strRefNo) AS refnum FROM claims
WHERE strRefNo LIKE '".$year."%'";
$statement = $connect->prepare($query);
if($statement->execute())
{
$result = $statement->fetchAll();
//$RefNo = '';
foreach($result as $row)
{
$RefNo = $row["refnum"];
if(empty($RefNo)){
$RefNo = $year.'-'. str_pad(1, 4, '0', STR_PAD_LEFT);
}else{
$array = explode("-",$RefNo);
$RefNo = $year.'-'.str_pad($array[1] + 1, 4, 0, STR_PAD_LEFT);
}
}
return $RefNo;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…