Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
Du füllst $this->count ab und fragst nachher nach $this->counter. Ist nicht das gleiche
<?php
class db
{
private $connection = NULL;
private $result = NULL;
private $counter=NULL;
public function __construct($host=NULL, $database=NULL, $user=NULL, $pass=NULL)
{
$this->connection = new PDO("mysql:host=".$host.";dbname=".$database, $user, $pass);
}
public function disconnect()
{
unset( $this->connection );
}
public function query($query)
{
$this->result=$this->connection->query($query);
$this->counter=NULL;
}
public function row()
{
return $this->result->fetch(PDO::FETCH_OBJ);
}
public function xarray()
{
return $this->result->fetch(PDO::FETCH_ASSOC);
}
public function numrows()
{
return $this->result->rowCount();
}
public function count()
{
if($this->counter==NULL && is_resource($this->result))
{
$this->counter = $this->result->rowCount();
}
return $this->counter;
}
}
Array ( [0] => Array (
[id] => 1 [anrede] => Herr [vorname] => test [nachname] => Musttest [strasse] => blub [plz] => 99999 [ort] =>test [email] => testqtest.de [telefon] =>0125698 [username] => [passwort] => [status] => [session] => ) [1] => Array ( [id] => 2 [anrede] => Frau [vorname] => dsgfdg [nachname] => dfgdf [strasse] => gdfgdf [plz] => gdfgdf [ort] => gdfgsdfg [email] => fgdfgs [telefon] => dfgdfgdf [kundennummer] => 45869596 [username] => [passwort] => [status] => [session] => ) )
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
include ('db2.php');
include ('conf.php');
$db = new db("mysql:host=localhost;port=3306;dbname=test", "test", "+++++");
/
$results = $db->select("test");
echo'
<table cellpadding="0" cellspacing="0" border="0" class="kunden">
<thead><tr>
<th class="thkopf"align="left">id</th>
<th class="thkopf"align="left">Vorname</th>
<th class="thkopf"align="left">Nachname</th>
<th class="thkopf"align="left">test</th>
<th class="thkopf"align="left">Aktion</th>
</tr></thead><tbody>
';
while ($abf = $result){
echo'
<tr>
<td class="tdbody"align="left">'.$abf['id'].'</td>
<td class="tdbody"align="left">'.$abf['vorname'].'</td>
<td class="tdbody"align="left">'.$abf['nachname'].'</td>
<td class="tdbody"align="left">
<a><img onclick="load(\'kundenbox_text\',\'pages/kunden/edit.php?kid='.$abf['id'].'\',\'kundenbox_head\',\'Kunden bearbeiten\');"src="image/edit.gif" border="0" alt="" /></a> <a href="javascript:kdel('.$abf['id'].');"><img src="image/del.gif" border="0" alt="" /></a>
</td>
</tr>'
;
}
echo'</tbody></table>';
echo "<div align=\"left\">";
?>
<?php
/**
* @name: db.php
*
* Datenbank Klasse simple
* Verbindung über die PDO herstellen
*
* @author Splasch
* @version 1
* @copyright Copyright (c) 2012, Splasch
**/
final class Db
{
static protected $db_obj = null; # Datenbank Objekt PDO
private $_user = 'xxx'; # Benutzername
private $_password = 'xxxx'; # Password
private $_datenbank = 'xxxx'; # Datenbankname
/**
* PDO verbindung aufbauen *
*/
public function connect()
{
try
{
return NEW PDO ('mysql:host=localhost; dbname='.$this->_datenbank,$this->_user,$this->_password,array
(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET CHARACTER SET utf8',
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
)
);
}
catch (PDOException $e)
{
echo 'Fehler beim Öffnen der Datenbank: ' . $e->getMessage();
}
}
}
<?php
$db = new Db();
$db = $db->connect();
$sql = 'SELECT
bla
FROM
xxx
WHERE
ID > 578';
foreach ($db -> query($sql as $row))
{
print_r($row);
}
// oder
$db = new Db();
$db = $db->connect();
$sql = "SELECT
id,username
FROM
user
WHERE
username = :username Limit 0,1 ";
$st = $db->prepare($sql);
$st->bindParam('username', $username, PDO::PARAM_STR);
$st->execute();
While($row = $st->fetch(PDO::FETCH_OBJ))
{
$user = $row->username;
echo $user."<br>";
}
// oder
$db = new Db();
$db = $db->connect();
$sql ="SELECT
SUM(einzahlung) - SUM(abbuchung) AS summe
FROM
buchungen";
$st = $db->prepare($sql);
$st ->execute();
$result = $st->fetch(PDO::FETCH_ASSOC);