query and fetch


#1

I have used this code for the last 4 years with no problem, after my provider upgraded to php 7 it has stopped working. I replaced all mysql references with mysqli and I am now able to connect with the database but the query and fetch function doesn’t work. How this is suppose to work is when the page is opened up the form queries the db and fills the text boxes with data from the db. It has to be the syntax of the query or the fetch function I would think but I can’t seem to find what is wrong now. I’m hoping someone takes a look at it and says " Hey stupid you just need to do this" Thanks for taking a look
Vince

if(!$this->DBLogin())
{
$this->logger->LogError(" DB Login Failed ");
//won’t complain
return true;
}
$this->logger->LogInfo(“login suceeded”);
$con = mysqli_connect($this->dbserver,$this->dbuser,$this->dbpwd,$this->dbname); //this connects to the db if the vars at the top are accurate
$result = mysqli_query($con,"select * from spread "); // this is the actual query here you feed in what you are looking for. call me on this
if($result === FALSE) // this is checking to see if the query returned any results if you see query failed in the log then it didn’t
{
$this->logger->LogError(“query failed”);
die(mysqli_error()); // TODO: better error handling
}

    // the next bit is what actually fetches the data into the form  it will grab the last row in the db
    // I still need to work on more complicated queries but that can be done
    while($row = mysqli_fetch_array($result))
   {
    $formvars['Textbox'] = $row['Week1']; // the formvars label is the name of the object on the form
    $formvars['Textbox1'] = $row['GM1_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox2'] = $row['GM1_SPREAD'];  // these have to match exactly
    $formvars['Textbox3'] = $row['GM1_AWAY_TEAM'];
    $formvars['Textbox4'] = $row['Day1'];
	$formvars['Textbox5'] = $row['GM2_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox6'] = $row['GM2_SPREAD'];  // these have to match exactly
    $formvars['Textbox7'] = $row['GM2_AWAY_TEAM'];
    $formvars['Textbox8'] = $row['Day2'];
	$formvars['Textbox9'] = $row['GM3_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox10'] = $row['GM3_SPREAD'];  // these have to match exactly
    $formvars['Textbox11'] = $row['GM3_AWAY_TEAM'];
    $formvars['Textbox12'] = $row['Day3'];
	$formvars['Textbox13'] = $row['GM4_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox14'] = $row['GM4_SPREAD'];  // these have to match exactly
    $formvars['Textbox15'] = $row['GM4_AWAY_TEAM'];
    $formvars['Textbox16'] = $row['Day4'];
	$formvars['Textbox17'] = $row['GM5_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox18'] = $row['GM5_SPREAD'];  // these have to match exactly
    $formvars['Textbox19'] = $row['GM5_AWAY_TEAM'];
    $formvars['Textbox20'] = $row['Day5'];
	$formvars['Textbox21'] = $row['GM6_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox22'] = $row['GM6_SPREAD'];  // these have to match exactly
    $formvars['Textbox23'] = $row['GM6_AWAY_TEAM'];
    $formvars['Textbox24'] = $row['Day6'];
	$formvars['Textbox25'] = $row['GM7_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox26'] = $row['GM7_SPREAD'];  // these have to match exactly
    $formvars['Textbox27'] = $row['GM7_AWAY_TEAM'];
    $formvars['Textbox28'] = $row['Day7'];
	$formvars['Textbox29'] = $row['GM8_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox30'] = $row['GM8_SPREAD'];  // these have to match exactly
    $formvars['Textbox31'] = $row['GM8_AWAY_TEAM'];
    $formvars['Textbox32'] = $row['Day8'];
	$formvars['Textbox33'] = $row['GM9_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox34'] = $row['GM9_SPREAD'];  // these have to match exactly
    $formvars['Textbox35'] = $row['GM9_AWAY_TEAM'];
    $formvars['Textbox36'] = $row['Day9'];
	$formvars['Textbox37'] = $row['GM10_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox38'] = $row['GM10_SPREAD'];  // these have to match exactly
    $formvars['Textbox39'] = $row['GM10_AWAY_TEAM'];
    $formvars['Textbox40'] = $row['day10'];
	$formvars['Textbox41'] = $row['GM11_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox42'] = $row['GM11_SPREAD'];  // these have to match exactly
    $formvars['Textbox43'] = $row['GM11_AWAY_TEAM'];
    $formvars['Textbox44'] = $row['day11'];
	$formvars['Textbox45'] = $row['GM12_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox46'] = $row['GM12_SPREAD'];  // these have to match exactly
    $formvars['Textbox47'] = $row['GM12_AWAY_TEAM'];
    $formvars['Textbox48'] = $row['day12'];
	$formvars['Textbox49'] = $row['GM13_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox50'] = $row['GM13_SPREAD'];  // these have to match exactly
    $formvars['Textbox51'] = $row['GM13_AWAY_TEAM'];
    $formvars['Textbox52'] = $row['day13'];
	$formvars['Textbox53'] = $row['GM14_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox54'] = $row['GM14_SPREAD'];  // these have to match exactly
    $formvars['Textbox55'] = $row['GM14_AWAY_TEAM'];
    $formvars['Textbox56'] = $row['day14'];
	$formvars['Textbox57'] = $row['GM15_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox58'] = $row['GM15_SPREAD'];  // these have to match exactly
    $formvars['Textbox59'] = $row['GM15_AWAY_TEAM'];
    $formvars['Textbox60'] = $row['day15'];
	$formvars['Textbox61'] = $row['GM16_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox62'] = $row['GM16_SPREAD'];  // these have to match exactly
    $formvars['Textbox63'] = $row['GM16_AWAY_TEAM'];
    $formvars['Textbox64'] = $row['day16'];
	$formvars['Textbox65'] = $row['STB_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox66'] = $row['STB_SPREAD'];  // these have to match exactly
    $formvars['Textbox67'] = $row['STB_AWAY_TEAM'];
    $formvars['Textbox68'] = $row['daySTB'];
	$formvars['Textbox69'] = $row['MTB_HOME_TEAM']; // the row label is the column name from the database
    $formvars['Textbox70'] = $row['MTB_SPREAD'];  // these have to match exactly
    $formvars['Textbox71'] = $row['MTB_AWAY_TEAM'];
    $formvars['Textbox72'] = $row['dayMTB'];
   }
    
    mysqli_close($this->db);
  
    return true;
}

// this function isn't stricly necessary but it is useful for debugging it will let you know if the db is unreachable
function DBLogin()
{
    //connect to DB
    $this->db = mysqli_connect($this->dbserver,$this->dbuser,$this->dbpwd);
    $this->logger->LogInfo("reached dblogin");
    if(!$this->db)
    {
        $this->logger->LogInfo("mysqli connect fail");
        return false;
        
    }

    if(!mysqli_select_db($this->dbname,$this->db))
    {
       $this->logger->LogInfo("mysqli select fail");
       return false;
    }
    return true;
}