add doku
This commit is contained in:
@@ -2,49 +2,100 @@
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
|
||||
namespace database;
|
||||
|
||||
/**
|
||||
* The SQLManager manage the SQL-Connection for an API
|
||||
*
|
||||
* @author stubbfel
|
||||
* @since 20.06.2013
|
||||
*/
|
||||
class SQLManager {
|
||||
|
||||
/**
|
||||
* Variable for address of the server
|
||||
* @var string
|
||||
*/
|
||||
private $serverAddress;
|
||||
|
||||
/**
|
||||
* Variable for name of the databaseuser
|
||||
* @var string
|
||||
*/
|
||||
private $userName;
|
||||
|
||||
/**
|
||||
* Variable for name of the database
|
||||
* @var string
|
||||
*/
|
||||
private $dbName;
|
||||
|
||||
/**
|
||||
* Variable for password of the user
|
||||
* @var string
|
||||
*/
|
||||
private $userPw;
|
||||
|
||||
/**
|
||||
* Variable for link of the connection to the server
|
||||
* @var connection
|
||||
*/
|
||||
private $link;
|
||||
|
||||
public function __construct() {
|
||||
include_once PATH_DATABASE . "/mysql.php";
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
public function SQLManager() {
|
||||
include_once PATH_CONFIG . "/config.db.php";
|
||||
$this->serverAddress = $sqlServer;
|
||||
$this->dbName = $sqlDBName;
|
||||
$this->userName = $sqlDBUser;
|
||||
$this->userPw = $sqlDBUserPW;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default-DEConstructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
$this->close();
|
||||
$this->closeConnection();
|
||||
$this->serverAddress = null;
|
||||
$this->dbName = null;
|
||||
$this->userName = null;
|
||||
$this->userPW = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setup the connection to the Database
|
||||
*/
|
||||
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());
|
||||
$this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw);
|
||||
if (!$this->link) {
|
||||
exit("No Connection: " . mysql_error());
|
||||
}
|
||||
$selected = mysql_select_db($this->dbName, $this->link);
|
||||
if (!$selected) {
|
||||
exit("No DB: " . mysql_error());
|
||||
}
|
||||
}
|
||||
|
||||
public function close() {
|
||||
/**
|
||||
* Method close the connection
|
||||
*/
|
||||
public function closeConnection() {
|
||||
if ($this->link) {
|
||||
mysql_close($this->link);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method send a query to the Datebase and return the result
|
||||
* @param string $query
|
||||
* @return result[num][assoc]
|
||||
*/
|
||||
protected function query($query) {
|
||||
$mysqlResult = mysql_query($query, $this->link) or die("Query error: " . mysql_error());
|
||||
|
||||
$mysqlResult = mysql_query($query, $this->link);
|
||||
if (!$mysqlResult) {
|
||||
exit("Query error: " . mysql_error());
|
||||
}
|
||||
$rowNums = mysql_num_rows($mysqlResult);
|
||||
$result = array();
|
||||
for ($i = 0; $i < $rowNums; $i++) {
|
||||
|
||||
Reference in New Issue
Block a user