Umstellen von PHP5 auf PHP7

Irgendwelche Probleme mit XAMPP für Windows? Dann ist hier genau der richtige Ort um nachzufragen.

Umstellen von PHP5 auf PHP7

Postby finckenbusch » 01. March 2020 17:09

Habe vor ca 8 Jahren aus meinem Lehrbuch (PHP 5 & MySQL) eine Klasse übernommen zum auslesen und zur Ausgabe der Daten in eine Tabelle.
Schaffe es nicht diese Klasse in PHP 7 modifizieren.
Jetzt mache ich es ohne diese Klasse ist aber "sehr häßlich".
Vielleicht kann mir jemand helfen die Klasse auf PHP7 zu bringen.
Hier die Klasse. (blutdruck.inc)
Code: Select all
<?php

// MySQL Klassendefinition
//
//
// Methoden:
//   set_doerror($boolvalue))
//   int connect()
//   int query($sql)
//   echoerror()
//   array rowarray()
//   echoquery($sql)


class mysql_db {
   var $link = false;
   var $resid = false;
   var $doerror = false;
   var $host = "localhost";
   var $user = "xxxx";
   var $passwd = "xxxx";
   var $tables = "Blutdruck";
   

   function set_doerror($boolvalue)
   {
      $this->doerror = $boolvalue;
   }

   
function connect()
// Verbindet zur Datenbank
{
  $temp = @mysql_connect
    ($this->host, $this->user, $this->passwd);
  if (!$temp)
  {
    $this->echoerror();
    return false;
  }
  $this->link = $temp;
  $temp = @mysql_select_db($this->tables, $temp);
  if (!$temp)
  {
    $this->echoerror();
    return false;
  }
  return $this->link;
}


   
function query($sql)
// Sendet eine Anfrage an die Datenbank
{
  if (!$this->link)
  {
    if ($this->doerror)
    {
      echo ("<b>Nicht verbunden.</b><br>");
      return false;
    }
  }
  if ($this->resid) @mysql_free_result($this->resid);
  $result = mysql_query($sql, $this->link);
  if (!$result)  $this->echoerror();
  $this->resid = $result;
  return $result;
}

function echoerror()
// erzeugt eine Fehlerausschrift
// wenn $doerror=TRUE
{
  if (!$this->doerror) return;
  if (!mysql_errno()) return;
  echo ("<font color=\"red\"><b>" . mysql_errno());
  echo (": ". mysql_error() ." </b></font><br>");
}

function data()
// liefert einen Datensatz
{
  if (!$this->link)
  {
    if ($this->doerror)
      echo ("<b>Nicht verbunden!</b><br>");
    return false;
  }
  if (!$this->resid)
  {
    if ($this->doerror)
      echo ("<b>Keine Abfrage!</b><br>");
    return false;
  }
  $result = mysql_fetch_array($this->resid, MYSQL_BOTH);
  $this->echoerror();
  return $result;
}


function echoquery($sql)
//Fragt die Datenbank ab und stellt die Abfrage dar
{
  $this->query($sql);
  echo("<table border cellpadding=\"3\"><tr>");
  $index = 0;
  echo("<th>record</th>");
  while ($field = mysql_fetch_field($this->resid))
    echo("<th>$field->name</th>");
  echo ("</tr>\n");
  $rec=0;
  while ($row = $this->data())
  {
    $rec++;
    echo("<tr><td>$rec</td>");
    for ($i=0; $i<mysql_num_fields($this->resid); $i++)
      echo("<td>".htmlentities($row[$i])."&nbsp;</td>");
    echo("</tr>\n");
  }
  echo ("</table>");
}

/*
function set_doerror($boolvalue)
{
  $this->doerror = $boolvalue;
}
*/

function mysql_db()
// Construktor
{
  $this->connect();
}

}
   
   
$db = new mysql_db;
   
?>



Aufgerufen wird sie mit der Seite "blutdruck_daten.php"
Code: Select all
<?php

 
include("blutdruck.inc");

 
  $db->echoquery("select Nr, Fecha,TIME, Presion_alta, Presion_baja, Pulso, Peso from werte  ORDER BY Nr DESC");

?>



"echoquery" muss ich natürlich auch noch anpassen.
Wäre super wenn mir jemand helfen könnte :roll:
finckenbusch
 
Posts: 10
Joined: 02. January 2020 18:16
XAMPP version: windows-x64-7.3.5-1-VC15
Operating System: Win10

Return to XAMPP für Windows

Who is online

Users browsing this forum: No registered users and 112 guests