我有一个小小的webprojekt。我用OOP PHP编写的第一个项目,因此我需要你的帮助。
我的项目: 有一个带有数据库配置设置的config.ini。
db_connection.php
<?php
/**
* Database connection File
*
* Database connection
*
*/
//read the .ini file and create an assoziative array
$db = parse_ini_file("config.ini");
$db_user = $db['user'];
$db_pass = $db['pass'];
$db_name = $db['name'];
$db_host = $db['host'];
$db_type = $db['type'];
$db_port = $db['port'];
try
{
$pdo = new PDO('mysql:host='. $db_host .';port=' . $db_port . ';dbname='.$db_name, $db_user, $db_pass);
echo "Connected!";
}
catch (PDOException $e)
{
exit('Error Connecting To DataBase');
}
database.php中
<?php
/**
* Database queries
*
* Database queries with DROPDOWN-VALUES that are used in HTML-Template to select distinct groups of devices.
*
*
*/
class database
{
function __construct($pdo)
{
$this->pdo = $pdo;
}
//SQL-QUERY of all devices incl. credits and timestamps
//DROPDOWN VALUE 1
function getAllData()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices which correspond to the searchword incl. credits and timestamps
//SEARCHWORD
function searchword($searchword)
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID
WHERE g.Hersteller LIKE '$searchword'
OR g.Typ LIKE '$searchword'
OR g.Version LIKE '$searchword'
OR u.Firstname LIKE '$searchword'
OR u.Lastname LIKE '$searchword' ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices that are not available including timestamps, firstname and lastname
//DROPDOWN VALUE 2
function notAvailable()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM User u
LEFT JOIN Verliehen v
ON u.UID = v.UID
LEFT JOIN Geraet g
ON v.GID = g.GID
WHERE u.GID = g.GID ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices where "Art" is like 'Tablet' incl. credits and timestamps
//DROPDOWN VALUE 3
function tablet()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID
WHERE g.Art LIKE 'Tablet' ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices where "Art" is like 'Smartphone' incl. credits and timestamps
//DROPDOWN VALUE 4
function smartphone()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID
WHERE g.Art LIKE 'Smartphone' ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices where "Art" is like 'MP3-Player' incl. credits and timestamps
//DROPDOWN VALUE 5
function mp3Player()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID
WHERE g.Art LIKE 'MP3-Player' ; " ) ;
$query->execute();
return $query->fetchAll();
}
//SQL-QUERY of all devices where "Art" is like 'ebook Reader' incl. credits and timestamp
//DROPDOWN VALUE 6
function ebookReader()
{
$query = $this->pdo->prepare("SELECT g.Hersteller, g.Typ, g.Version, g.Art, v.Zeit, u.Firstname, u.Lastname
FROM Geraete g
LEFT JOIN Verliehen v
ON g.GID = v.GID
LEFT JOIN User u
ON u.UID = v.UID
WHERE g.Art LIKE 'ebook Reader' ; " ) ;
$query->execute();
return $query->fetchAll();
}
}
的index.php
<?php
/**
* Index File
*
* require of db_connection and database
*
*/
require_once 'db_connection.php';
require_once 'database.php';
$dbh = new database($pdo);
$rows = $dbh->getAllData();
var_dump($rows);
现在我的控制台和我的浏览器只显示我:已连接!数组(0){}
怎么了?