61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
include_once "../../global.inc.php";
|
|
|
|
/**
|
|
* The SQLManager manage the SQL-Connection for an API
|
|
*
|
|
* @author stubbfel
|
|
*/
|
|
class SQLManager {
|
|
|
|
private $serverAddress;
|
|
private $userName;
|
|
private $dbName;
|
|
private $userPw;
|
|
private $link;
|
|
|
|
public function __construct() {
|
|
include_once PATH_DATABASE . "/mysql.php";
|
|
$this->serverAddress = $sqlServer;
|
|
$this->dbName = $sqlDBName;
|
|
$this->userName = $sqlDBUser;
|
|
$this->userPw = $sqlDBUserPW;
|
|
}
|
|
|
|
public function __destruct() {
|
|
$this->close();
|
|
$this->serverAddress = null;
|
|
$this->dbName = null;
|
|
$this->userName = null;
|
|
$this->userPW = null;
|
|
}
|
|
|
|
public function connect() {
|
|
$this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw) or die("No Connection: " . mysql_error());
|
|
mysql_select_db($this->dbName, $this->link) or die("No DB: " . mysql_error());
|
|
}
|
|
|
|
public function close() {
|
|
if ($this->link) {
|
|
mysql_close($this->link);
|
|
}
|
|
}
|
|
|
|
protected function query($query) {
|
|
$mysqlResult = mysql_query($query, $this->link) or die("Query error: " . mysql_error());
|
|
|
|
$rowNums = mysql_num_rows($mysqlResult);
|
|
$result = array();
|
|
for ($i = 0; $i < $rowNums; $i++) {
|
|
$row = mysql_fetch_assoc($mysqlResult);
|
|
$result[$i] = $row;
|
|
}
|
|
mysql_free_result($mysqlResult);
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|