-
Notifications
You must be signed in to change notification settings - Fork 0
/
DbReader.php
45 lines (36 loc) · 864 Bytes
/
DbReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?
require_once("Parameters.php");
class DbReader
{
private $dbh;
private $selected;
public function Open()
{
$this->dbh = mysql_connect(Parameters::DbServerName, Parameters::DbUserName, Parameters::DbPassword)
or die("Unable to connect to MySQL");
$this->selected = mysql_select_db(Parameters::DbName, $this->dbh)
or die("Could not select database");
}
public function Close()
{
mysql_close($this->dbh);
}
public function Read($object, $objectId)
{
$query = "select * from $object";
if ($objectId != "*")
$query .= " where Id=$objectId";
$result = mysql_query($query) or die(mysql_error()."\n".$query);
$data = array();
$nbResult = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$nbResult++;
$data[$row["Id"]] = $row;
}
if ($nbResult > 0)
return $data;
return null;
}
}
?>