fixed missalign, upgraded DBLib
parent
01272e92b9
commit
f7774cfc38
|
|
@ -54,7 +54,7 @@ function validFile($filename){
|
||||||
|
|
||||||
function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
|
function logStats($datas,$type,$alt=false,$outlineAlt=0,$mode=1){
|
||||||
$output="";
|
$output="";
|
||||||
$left=80;
|
$left=10;
|
||||||
$max=getMax($type);
|
$max=getMax($type);
|
||||||
for($num=0;$num<=$max;$num++){
|
for($num=0;$num<=$max;$num++){
|
||||||
$printValues=true;
|
$printValues=true;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#08.08.12 OOP, proper Link handling #v4
|
#08.08.12 OOP, proper Link handling #v4
|
||||||
#25.08.12 construct;toString;set/getPrefix;noExecute added, LinkHandling fixed #v5
|
#25.08.12 construct;toString;set/getPrefix;noExecute added, LinkHandling fixed #v5
|
||||||
#04.09.12 various improvments #v5.2
|
#04.09.12 various improvments #v5.2
|
||||||
|
#04.02.14 port to mysqli #v6.1
|
||||||
|
|
||||||
class DBLib{
|
class DBLib{
|
||||||
|
|
||||||
|
|
@ -18,15 +19,20 @@ class DBLib{
|
||||||
private $devmode=false;
|
private $devmode=false;
|
||||||
private $dbprefix="";
|
private $dbprefix="";
|
||||||
private $connected=false;
|
private $connected=false;
|
||||||
const version=5.2;
|
const version=6.1;
|
||||||
private $dbinfo=null;
|
private $dbinfo=null;
|
||||||
private $execute=true;
|
private $execute=true;
|
||||||
|
|
||||||
public function __construct($host="",$user="",$pass="",$database=""){
|
public function __construct($host="",$user="",$pass="",$database=""){
|
||||||
if(($host!="" || $user!="" || $pass!="" || $database!="")){
|
if(($host!="" || $user!="" || $pass!="" || $database!="")){
|
||||||
$this->connect($host,$user,$pass,$database);
|
$this->connect($host,$user,$pass,$database);
|
||||||
|
}else{
|
||||||
|
$this->dbLink=new mysqli();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function __destruct(){
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
public function connect($host,$user,$pass,$database){
|
public function connect($host,$user,$pass,$database){
|
||||||
if(!$this->checkExecute('connect')){
|
if(!$this->checkExecute('connect')){
|
||||||
|
|
@ -34,8 +40,8 @@ class DBLib{
|
||||||
$this->dbinfo=array('user'=>'noExecute','host'=>'noExecute','dbbase'=>'noExecute');
|
$this->dbinfo=array('user'=>'noExecute','host'=>'noExecute','dbbase'=>'noExecute');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->dbLink=@mysql_connect($host, $user, $pass);
|
$this->dbLink=new mysqli($host, $user, $pass, $database);
|
||||||
if ($this->dbLink===false || !@mysql_select_db($database)) {
|
if ($this->dbLink->connect_errno != 0) {
|
||||||
$this->echoDev('Connection failed!');
|
$this->echoDev('Connection failed!');
|
||||||
$this->connected=false;
|
$this->connected=false;
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -46,11 +52,13 @@ class DBLib{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close(){
|
||||||
$this->connected=false;
|
if ($this->dbLink instanceof mysqli) {
|
||||||
|
$this->connected=$this->dbLink->close();
|
||||||
|
$this->dbLink=null;
|
||||||
|
}
|
||||||
if(!$this->checkExecute('close')){
|
if(!$this->checkExecute('close')){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mysql_close($this->dbLink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($table, $values, $identifier=array(), $increment=false,$escapeIdentifier=true) {
|
public function update($table, $values, $identifier=array(), $increment=false,$escapeIdentifier=true) {
|
||||||
|
|
@ -75,12 +83,7 @@ class DBLib{
|
||||||
if(!$this->checkExecute($sql)){
|
if(!$this->checkExecute($sql)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result=mysql_query($sql,$this->dbLink);
|
return $this->executeSQL($sql);
|
||||||
if(mysql_errno()){
|
|
||||||
return false;
|
|
||||||
}else{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert($table, $values) {
|
public function insert($table, $values) {
|
||||||
|
|
@ -101,12 +104,7 @@ class DBLib{
|
||||||
if(!$this->checkExecute($sql)){
|
if(!$this->checkExecute($sql)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result = mysql_query($sql,$this->dbLink);
|
return $this->executeSQL($sql);
|
||||||
if (mysql_errno()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public function delete($table,$identifier,$extra="",$escapeIdentifier=true){
|
public function delete($table,$identifier,$extra="",$escapeIdentifier=true){
|
||||||
if(empty($table) || !$this->connected){
|
if(empty($table) || !$this->connected){
|
||||||
|
|
@ -119,12 +117,7 @@ class DBLib{
|
||||||
if(!$this->checkExecute($sql)){
|
if(!$this->checkExecute($sql)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result=mysql_query($sql,$this->dbLink);
|
return $this->executeSQL($sql);
|
||||||
if(mysql_errno()){
|
|
||||||
return false;
|
|
||||||
}else{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function select($table, $values, $identifier=array(), $extra="",$escapeIdentifier=true) {
|
public function select($table, $values, $identifier=array(), $extra="",$escapeIdentifier=true) {
|
||||||
|
|
@ -142,9 +135,9 @@ class DBLib{
|
||||||
if(!$this->checkExecute($sql)){
|
if(!$this->checkExecute($sql)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result = mysql_query($sql,$this->dbLink);
|
$result = $this->dbLink->query($sql);
|
||||||
if (!mysql_errno()) {
|
if ($this->dbLink->errno == 0) {
|
||||||
while($out=mysql_fetch_assoc($result)){
|
while($out=$result->fetch_assoc()){
|
||||||
$output[]=$out;
|
$output[]=$out;
|
||||||
}
|
}
|
||||||
if(sizeof($output)==0){
|
if(sizeof($output)==0){
|
||||||
|
|
@ -152,6 +145,16 @@ class DBLib{
|
||||||
}
|
}
|
||||||
return($output);
|
return($output);
|
||||||
} else {
|
} else {
|
||||||
|
$this->echoDev("query failed: ".$this->dbLink->error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function executeSQL($sql){
|
||||||
|
$this->dbLink->query($sql);
|
||||||
|
if ($this->dbLink->errno == 0) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +169,7 @@ class DBLib{
|
||||||
|
|
||||||
public function dbEscape($string) {
|
public function dbEscape($string) {
|
||||||
if($this->connected && $this->execute){
|
if($this->connected && $this->execute){
|
||||||
return(mysql_real_escape_string($string,$this->dbLink));
|
return($this->dbLink->escape_string($string));
|
||||||
}else{
|
}else{
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue