note 128466 added to book.pdo
| From: | estargon at main dot php dot net | Date: | Tue, 09 May 2023 10:07:10 +0000 |
| Subject: | note 128466 added to book.pdo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220421@lists.php.net to get a copy of this message | ||
<?php
require_once "inc/connection_function.inc.php";
class Filiale{
private $f_id;
private $f_ort;
private $f_anz_mit;
private static $dbh;
public function __construct($ort){
$result=self::$dbh->prepare("SELECT * FROM filiale WHERE f_ort = :ort");
$result->bindParam(":ort",$ort);
$result->execute();
$anzahl=$result->rowCount(); //Anzahl der Datensätze lesen
if ($anzahl==0){
$this->f_ort=$ort;
echo"<br><div>Keine Eintraege vorhanden. Filiale $this->f_ort
ange-legt.</div>";
}
else
{
foreach($result as $row){
$this->f_id=$row['f_id'];
$this->f_ort = $row['f_ort'];
}
echo "<br><div>Filiale existiert und wurde aus DB
gelesen.</div>";
}
}
public static function connect2db(){
try
{
self::$dbh = connectDB();
echo "DB-Verbinung erfolgreich!<br>";
}
catch (PDOException $e) {}
}
public function saveInDB(){
try
{
$stmt=self::$dbh->prepare("INSERT INTO filiale VALUES (?,?)");
$stmt->execute(array($this->f_id,$this->f_ort));
$this->f_id=self::$dbh->lastInsertId();
echo "<br>Filiale erfolgreich in DB gespeichert.<br>";
}
catch (PDOException $e){
if($e->getCode() == "23000"){
echo "Keine Eintragung erfolgt, da Anlagen-Nr. ".$this->f_id."
bereits
angelegt<br>";
}
else{
echo "Datenbankfehler: ".$e->getMessage()."<br>";
die("Skript abgebrochen<br>");
}
}
}
public static function showFilialen(){
try{
$result=self::$dbh->prepare("SELECT * FROM filiale");
$result->execute();
echo"<h3>Alle Filialen</h3>
<table border=1>
<tr>
<th>Filialnummer</th>
<th>Ort</th>
</tr>";
foreach ($result as $row){
echo "<tr>
<td>".$row['f_id']."</td>
<td>".$row['f_ort']."</td>
</tr>";
}
echo"</table>";
}
catch (PDOException $e){
if($e->getCode() == "23000") {
echo "Keine Eintragung erfolgt, da Anlagen-Nr. bereits angelegt<br>";
}
else {
echo "Datenbankfehler: ".$e->getMessage()."<br>"; die
("Skript abgebrochen<br>");
}
}
}
public function showMitarbeiter(){
try {
$result=self::$dbh->prepare("SELECT m_name FROM mitarbeiter, filiale WHE-RE
f_ID=? AND m_f_id=f_id");
$result->execute(array($this->f_id));
echo"<br><div>Mitarbeiter der Filiale:
".$this->f_ort."</div>";
foreach($result as $row){
echo $row["m_name"]."<br>";
}
}
catch (PDOException $e){
if($e->getCode() == "23000") {
echo "Keine Eintragung erfolgt, da Anlagen-Nr. bereits
angelegt<br>";
}
else {
echo "Datenbankfehler: ".$e->getMessage()."<br>"; die
("Skript abgebrochen<br>");
}
}
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 77.23.135.28)
----
Manual Page -- https://php.net/manual/en/book.pdo.php
Edit -- https://main.php.net/note/edit/128466
Del: integrated -- https://main.php.net/note/delete/128466/integrated
Del: useless -- https://main.php.net/note/delete/128466/useless
Del: bad code -- https://main.php.net/note/delete/128466/bad+code
Del: spam -- https://main.php.net/note/delete/128466/spam
Del: non-english -- https://main.php.net/note/delete/128466/non-english
Del: in docs -- https://main.php.net/note/delete/128466/in+docs
Del: other reasons-- https://main.php.net/note/delete/128466
Reject -- https://main.php.net/note/reject/128466
Search -- https://main.php.net/manage/user-notes.php