Initial checkin
This commit is contained in:
commit
d75eb444fc
4304 changed files with 369634 additions and 0 deletions
190
core/database/mysql.class.php
Normal file
190
core/database/mysql.class.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
/**
|
||||
* Project: astat - simple site engine
|
||||
* File: /core/database/mysql.class.php
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://www.astat.org SVN: $URL: http://svn.astat.org/astat/trunk/core/database/mysql.class.php $
|
||||
* @copyright 2025 becast.at
|
||||
* @author Bernhard Jaud <bernhard at becast dot at>
|
||||
* @package astat core
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
* @version $Id: mysql.class.php 104 2010-02-20 19:16:12Z genuineparts $
|
||||
*/
|
||||
|
||||
$module["db"]["name"]="Database Class (mysql)";
|
||||
$module["db"]["ver"]="1.0.1";
|
||||
class db {
|
||||
var $host="";
|
||||
var $user="root";
|
||||
var $password="";
|
||||
var $db="becast";
|
||||
var $encoding;
|
||||
var $logging;
|
||||
var $abfragen=0;
|
||||
var $exception;
|
||||
private $conid=FALSE;
|
||||
public const ASSOC = 1;
|
||||
public const NUM = 2;
|
||||
public const BOTH = 3;
|
||||
|
||||
function __construct($host,$user,$password,$db,$encoding="utf8",$logging=false,$exception=false) {
|
||||
global $log,$config;
|
||||
$this->host=$host;
|
||||
$this->user=$user;
|
||||
$this->password=$password;
|
||||
$this->db=$db;
|
||||
$this->logging=$logging;
|
||||
$this->exception=$exception;
|
||||
|
||||
if($this->logging==FALSE && DEBUG!=FALSE){
|
||||
$this->logger=new logger("file",dirname(dirname(dirname(__FILE__))).'/logs/mysql_debug.log',5);
|
||||
}elseif($this->logging){
|
||||
$this->logger=new logger("file",dirname(dirname(dirname(__FILE__))).'/logs/mysql.log');
|
||||
}
|
||||
|
||||
$this->encoding=$encoding;
|
||||
$this->conid;
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write("mySQL Klasse instanziert", 5);
|
||||
if(!$this->conid){
|
||||
if($this->logging)
|
||||
$this->logger->write("Connection zu mySQL Server besteht nicht.", 5,__LINE__,__FILE__);
|
||||
$this->conid=$this->connect($this->host,$this->user,$this->password,$this->db,$this->encoding);
|
||||
}else{
|
||||
if($this->logging)
|
||||
$this->logger->write("Connection zu mySQL Server besteht. ID ".$this->conid, 5,__LINE__,__FILE__);
|
||||
}
|
||||
if($this->encoding)
|
||||
$this->query("SET NAMES '".$this->encoding."'");
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
function connect($host, $user, $password, $db, $encoding){
|
||||
$conn = @mysql_connect($host, $user, $password);
|
||||
if($this->logging)
|
||||
$this->logger->write("Connect to Mysql Server", 5,__LINE__,__FILE__);
|
||||
|
||||
if(!$conn){
|
||||
if($this->exception){
|
||||
throw new Exception('mySQLi Connect failed');
|
||||
}else{
|
||||
trigger_error("mySQL Connect failed",E_USER_ERROR);
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write("Connect Failed ". $this->error(), 5,__LINE__,__FILE__);
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
if($this->logging)
|
||||
$this->logger->write("Selecting Database ".$db, 5,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
$conn2 = @mysql_select_db($db,$conn);
|
||||
if($this->logging)
|
||||
$this->logger->write("Connect to Mysql Server", 5,__LINE__,__FILE__);
|
||||
|
||||
if(!$conn2){
|
||||
include('templates/general_error.tpl');
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write("Select failed ". $this->error(), 5,__LINE__,__FILE__);
|
||||
die();
|
||||
}else{
|
||||
if($this->logging)
|
||||
$this->logger->write("Database ".$db." selected", 5,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
return $conn;
|
||||
}
|
||||
|
||||
|
||||
function disconnect(){
|
||||
if($this->logging)
|
||||
$this->logger->write("Closing Mysql Connection.", 5,__LINE__,__FILE__);
|
||||
|
||||
@mysql_close($this->conid);
|
||||
}
|
||||
|
||||
function query($query){
|
||||
global $abfragen;
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write($query." ". $this->conid, 5,__LINE__,__FILE__);
|
||||
|
||||
$this->abfragen++;
|
||||
$res = mysql_query($query, $this->conid);
|
||||
return $res;
|
||||
}
|
||||
|
||||
function querys(){
|
||||
return $this->abfragen;
|
||||
}
|
||||
|
||||
function num_rows($result){
|
||||
$rows = mysql_num_rows($result);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function fetch_row($result){
|
||||
$row = mysql_fetch_row($result);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function fetch_array($result){
|
||||
$row = array();
|
||||
$row = mysql_fetch_array($result, MYSQL_ASSOC);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function escape($string){
|
||||
$return = mysql_real_escape_string($string);
|
||||
return $return;
|
||||
}
|
||||
|
||||
function escape_binary($string){
|
||||
return "X'".$this->escape(bin2hex($string))."'";
|
||||
}
|
||||
|
||||
function fetch_object($result){
|
||||
$row = mysql_fetch_object($result);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function error(){
|
||||
$error = mysql_error($this->conid);
|
||||
return $error;
|
||||
}
|
||||
|
||||
function errno(){
|
||||
$errno = mysql_errno($this->conid);
|
||||
return $errno ;
|
||||
}
|
||||
|
||||
function free_result($result){
|
||||
mysql_free_result($result);
|
||||
}
|
||||
|
||||
function last_id(){
|
||||
$id = mysql_insert_id($this->conid);
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
?>
|
181
core/database/mysqli.class.php
Normal file
181
core/database/mysqli.class.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/**
|
||||
* Project: astat - simple site engine
|
||||
* File: /core/database/mysqli.class.php
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* @link http://www.astat.org SVN: $URL: http://svn.astat.org/astat/trunk/core/database/mysqli.class.php $
|
||||
* @copyright 2025 becast.at
|
||||
* @author Bernhard Jaud <bernhard at becast dot at>
|
||||
* @package astat core
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
* @version $Id: mysqli.class.php 126 2010-02-21 21:07:52Z genuineparts $
|
||||
*/
|
||||
|
||||
$module["db"]["name"]="Database Class (mysqli)";
|
||||
$module["db"]["ver"]="1.0.1";
|
||||
class db {
|
||||
var $mysqli;
|
||||
var $host="";
|
||||
var $user="root";
|
||||
var $password="";
|
||||
var $db="astat";
|
||||
var $encoding;
|
||||
var $logger;
|
||||
var $logging;
|
||||
var $abfragen=0;
|
||||
var $exception;
|
||||
public const ASSOC = 1;
|
||||
public const NUM = 2;
|
||||
public const BOTH = 3;
|
||||
|
||||
function __construct($host,$user,$password,$db,$encoding="utf8",$logging=false,$exception=false) {
|
||||
global $log,$config,$root,$logger;
|
||||
$this->mysqli;
|
||||
$this->host=$host;
|
||||
$this->user=$user;
|
||||
$this->password=$password;
|
||||
$this->db=$db;
|
||||
$this->logging=$logging;
|
||||
$this->exception=$exception;
|
||||
if($this->logging!=FALSE || DEBUG!=FALSE){
|
||||
$this->logger=new logger("file",dirname(dirname(dirname(__FILE__))).'/logs/mysql_debug.log',5);
|
||||
}
|
||||
$this->encoding=$encoding;
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write("mySQLi Klasse instanziert", 5,__LINE__,__FILE__);
|
||||
|
||||
if(!is_object($this->mysqli)){
|
||||
if($this->logging)
|
||||
$this->logger->write("Connection zu mySQL Server besteht nicht.", 5,__LINE__,__FILE__);
|
||||
|
||||
$this->connect($this->host,$this->user,$this->password,$this->db);
|
||||
}else{
|
||||
if($this->logging)
|
||||
$this->logger->write("Connection zu mySQL Server besteht.", 5,__LINE__,__FILE__);
|
||||
}
|
||||
if($this->encoding)
|
||||
$this->mysqli->set_charset($this->encoding);
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
function connect($host, $user, $password, $db){
|
||||
$this->mysqli=@new mysqli($host, $user, $password,$db);
|
||||
if($this->logging)
|
||||
$this->logger->write("Connect to Mysql Server", 5,__LINE__,__FILE__);
|
||||
|
||||
if (mysqli_connect_errno()) {
|
||||
if($this->exception){
|
||||
throw new Exception('mySQLi Connect failed');
|
||||
}else{
|
||||
if($this->logging)
|
||||
$this->logger->write("Connect Failed ". mysqli_connect_error(), 2,__LINE__,__FILE__);
|
||||
|
||||
trigger_error("mySQLi Connect failed",E_USER_ERROR);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function disconnect(){
|
||||
if($this->logging)
|
||||
$this->logger->write("Closing Mysqli Connection.", 5,__LINE__,__FILE__);
|
||||
|
||||
$this->mysqli->close();
|
||||
}
|
||||
|
||||
function query($query){
|
||||
global $abfragen;
|
||||
|
||||
if($this->logging)
|
||||
$this->logger->write($query, 5);
|
||||
|
||||
$this->abfragen++;
|
||||
|
||||
$res = $this->mysqli->query($query);
|
||||
if($this->mysqli->error && $this->logging){
|
||||
$this->logger->write("SQL ERROR: ".$this->mysqli->error,2);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function querys(){
|
||||
return $this->abfragen;
|
||||
}
|
||||
|
||||
function num_rows($result){
|
||||
$rows = $result->num_rows;
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function fetch_row($result){
|
||||
$row = $result->fetch_row();
|
||||
return $row;
|
||||
}
|
||||
|
||||
function fetch_array($result){
|
||||
|
||||
$row = array();
|
||||
$row = $result->fetch_array(MYSQLI_ASSOC);
|
||||
return $row;
|
||||
}
|
||||
|
||||
function fetch_array_num($result){
|
||||
|
||||
$row = array();
|
||||
$row = $result->fetch_array(MYSQLI_NUM );
|
||||
return $row;
|
||||
}
|
||||
|
||||
function escape($string){
|
||||
$return = $this->mysqli->real_escape_string($string);
|
||||
return $return;
|
||||
}
|
||||
|
||||
function escape_binary($string){
|
||||
return "X'".$this->escape(bin2hex($string))."'";
|
||||
}
|
||||
|
||||
function fetch_object($result){
|
||||
$row = $result->fetch_object();
|
||||
return $row;
|
||||
}
|
||||
|
||||
function error(){
|
||||
$error = $this->mysqli->error;
|
||||
return $error;
|
||||
}
|
||||
|
||||
function errno(){
|
||||
$errno = $this->mysqli->errno;
|
||||
return $errno ;
|
||||
}
|
||||
|
||||
function free_result($result){
|
||||
$result->free_result();
|
||||
}
|
||||
|
||||
function last_id(){
|
||||
$id = $this->mysqli->insert_id;
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue