<?php
/*
Simple MySQL Class
by MarWit ©
*/
if( !defined( 'IN_BLOG' ) ) exit(0);
include_once ROOT . '/config.php';
class MySQL {
private $mysqlInfo = Array( );
private $mysqlHandle = NULL;
public function __construct( $sqlInfo ) {
$this->mysqlInfo = $sqlInfo;
$this->mysqlHandle = mysql_connect( $sqlInfo[ 'host' ], $sqlInfo[ 'user' ], $sqlInfo[ 'password' ] );
mysql_select_db( $sqlInfo[ 'database' ] );
}
public function execQuery( $query ) {
return mysql_query( $query, $this->mysqlHandle );
}
public function selectTable( $table, $content = Array(), $specification = Array(), $other = '' ) {
$what = '';
$where = '';
if( empty( $content ) )
$what = '*';
else
foreach( $content as $i => $row ) $what .= $row . ( $i == count( $content ) ? '' : ',' );
if( empty( $specification ) )
$where = '';
else
{
$where = 'WHERE ';
foreach( $specification as $i => $item )
$where .= "`$i`='$item'" . ( $item == end( $specification ) ? ';' : ' AND ' );
}
return mysql_query( "SELECT $what FROM `{$this->mysqlInfo[ 'prefix' ]}$table` $where $other" );
}
public function insertData( $table, $content = Array() )
{
$data = Array( '', '' );
foreach( $content as $i => $x )
{
if( $data[ 0 ] == '' )
{
$data[ 0 ] .= '`' . mysql_escape_string( $i ) . '`';
$data[ 1 ] .= '\'' . mysql_escape_string( $x ) . '\'';
}
else
{
$data[ 0 ] .= ', `' . mysql_escape_string( $i ) . '`';
$data[ 1 ] .= ', \'' . mysql_escape_string( $x ) . '\'';
}
}
return mysql_query( "INSERT INTO `{$this->mysqlInfo[ 'prefix' ]}$table` ( {$data[ 0 ]} ) VALUES ( {$data[ 1 ]} )" );
}
public function removeData( $table, $content = Array(), $specification = Array(), $other = '' )
{
$what = '';
$where = '';
if( empty( $content ) )
$what = '*';
else
foreach( $content as $i => $row ) $what .= $row . ( $i == count( $content ) ? '' : ',' );
if( empty( $specification ) )
$where = '';
else
{
$where = 'WHERE ';
foreach( $specification as $i => $item )
$where .= "`$i`='$item'" . ( $item == end( $specification ) ? ';' : ' AND ' );
}
return mysql_query( "DELETE $what FROM `{$this->mysqlInfo[ 'prefix' ]}$table` $where $other" );
}
}
?>