Hi I have a problem with this method and it's driving me crazy.The query below should return one field from the database, an id where the filename is matched. Only one value should be returned. When I run the query I get an SQL object returned which looks fine:
mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 0 [type] => 0 )
However I cannot access the above query object no matter what way I try or at least I'm getting no value out of it. I did the exact same to get the package id and it works perfectly.
I used $row = $result_package_id->fetch_array(MYSQLI_ASSOC); to get the package_id and I tried that for the module_id but it didn't work. Tried the mysqli_fetch_array and it doesn't work either. At a loss of what to do next can anyone help?
ADDED getPackageId method and if statement where the two methods are called. Every time a query is successful the id and package id are retrieved and a new object is created with the two values.
function getId($fileName){
$con = connect();
if (!$con) {
trigger_error(mysqli_error($con), E_USER_ERROR);
die('Could not connect: ' . mysqli_error($con));
}
$yModuleId = 0;
$sql_filename = mysqli_real_escape_string($con, $fileName);
$query_module_id = "SELECT id FROM y_module WHERE fileName='" . $sql_filename . "'";
$result_module_id = mysqli_query($con, $query_module_id);
while($row_model = mysqli_fetch_array($result_module_id)){
$yModuleId = $row_model['id'];
return $yModuleId;
}
}
function getYPackageId($package_name){
$con = connect();
if (!$con) {
trigger_error(mysqli_error($con), E_USER_ERROR);
die('Could not connect: ' . mysqli_error($con));
}
$sql_packageName = mysqli_real_escape_string($con, $package_name);
$query_package_id = "SELECT id FROM y_package WHERE name='" . $package_name . "'";
$result_package_id = mysqli_query($con, $query_package_id) or die("__LINE__ : " . mysqli_error($con));
while($row_package = mysqli_fetch_array($result_package_id)){
$yPackageId = $row_package['id'];
print_r($yPackageId);
print_r("</br>");
print_r("</br>");
return $yPackageId;
};
}
if($result_model && $result_package && $result_model_package) {
$yModuleId = getId($fileName);
$yPackageId = getYPackageId($package_name);
$yIdObject = new YIds($yModuleId, $yaPackageId);
$yIdObjects [] = $yIdObject;
mysqli_query($con, "COMMIT");
$message = array("success", "[SUCCESS]", "Model published successfully.",$module_id);
}