2013-07-05 16:04:06 +00:00
< ? php
/*abstract*/ class Min_SQL {
var $_conn ;
/** Create object for performing database operations
* @ param Min_DB
*/
2015-08-15 15:04:21 +00:00
function __construct ( $connection ) {
2013-07-05 16:04:06 +00:00
$this -> _conn = $connection ;
}
2013-07-10 00:38:13 +00:00
/** Select data from table
* @ param string
* @ param array result of $adminer -> selectColumnsProcess ()[ 0 ]
* @ param array result of $adminer -> selectSearchProcess ()
* @ param array result of $adminer -> selectColumnsProcess ()[ 1 ]
* @ param array result of $adminer -> selectOrderProcess ()
* @ param int result of $adminer -> selectLimitProcess ()
* @ param int index of page starting at zero
2014-01-09 07:14:37 +00:00
* @ param bool whether to print the query
2013-07-10 00:38:13 +00:00
* @ return Min_Result
*/
2014-01-15 16:23:26 +00:00
function select ( $table , $select , $where , $group , $order = array (), $limit = 1 , $page = 0 , $print = false ) {
2013-07-10 00:38:13 +00:00
global $adminer , $jush ;
$is_group = ( count ( $group ) < count ( $select ));
$query = $adminer -> selectQueryBuild ( $select , $where , $group , $order , $limit , $page );
if ( ! $query ) {
$query = " SELECT " . limit (
2018-01-11 15:21:33 +00:00
( $_GET [ " page " ] != " last " && $limit != " " && $group && $is_group && $jush == " sql " ? " SQL_CALC_FOUND_ROWS " : " " ) . implode ( " , " , $select ) . " \n FROM " . table ( $table ),
2013-07-10 00:38:13 +00:00
( $where ? " \n WHERE " . implode ( " AND " , $where ) : " " ) . ( $group && $is_group ? " \n GROUP BY " . implode ( " , " , $group ) : " " ) . ( $order ? " \n ORDER BY " . implode ( " , " , $order ) : " " ),
( $limit != " " ? + $limit : null ),
( $page ? $limit * $page : 0 ),
" \n "
);
}
2014-02-24 02:34:00 +00:00
$start = microtime ( true );
$return = $this -> _conn -> query ( $query );
2014-01-09 07:14:37 +00:00
if ( $print ) {
2014-03-11 16:37:56 +00:00
echo $adminer -> selectQuery ( $query , format_time ( $start ));
2014-01-09 07:14:37 +00:00
}
2014-02-24 02:34:00 +00:00
return $return ;
2013-07-10 00:38:13 +00:00
}
2013-07-05 16:04:06 +00:00
/** Delete data from table
* @ param string
* @ param string " WHERE ... "
* @ param int 0 or 1
* @ return bool
*/
function delete ( $table , $queryWhere , $limit = 0 ) {
$query = " FROM " . table ( $table );
return queries ( " DELETE " . ( $limit ? limit1 ( $query , $queryWhere ) : " $query $queryWhere " ));
}
2013-07-05 22:32:15 +00:00
/** Update data in table
* @ param string
2013-07-06 17:31:21 +00:00
* @ param array escaped columns in keys , quoted data in values
2013-07-05 22:32:15 +00:00
* @ param string " WHERE ... "
* @ param int 0 or 1
2013-07-06 17:31:21 +00:00
* @ param string
2013-07-05 22:32:15 +00:00
* @ return bool
*/
2013-07-06 17:31:21 +00:00
function update ( $table , $set , $queryWhere , $limit = 0 , $separator = " \n " ) {
$values = array ();
foreach ( $set as $key => $val ) {
$values [] = " $key = $val " ;
}
$query = table ( $table ) . " SET $separator " . implode ( " , $separator " , $values );
2013-07-05 22:32:15 +00:00
return queries ( " UPDATE " . ( $limit ? limit1 ( $query , $queryWhere ) : " $query $queryWhere " ));
}
2013-07-05 16:04:06 +00:00
/** Insert data into table
* @ param string
2013-07-06 17:31:21 +00:00
* @ param array escaped columns in keys , quoted data in values
2013-07-05 16:04:06 +00:00
* @ return bool
*/
function insert ( $table , $set ) {
2013-07-06 17:31:21 +00:00
return queries ( " INSERT INTO " . table ( $table ) . ( $set
? " ( " . implode ( " , " , array_keys ( $set )) . " ) \n VALUES ( " . implode ( " , " , $set ) . " ) "
2013-08-08 21:50:43 +00:00
: " DEFAULT VALUES "
2013-07-06 17:31:21 +00:00
));
2013-07-05 16:04:06 +00:00
}
/** Insert or update data in table
* @ param string
* @ param array
2013-07-09 18:34:12 +00:00
* @ param array of arrays with escaped columns in keys and quoted data in values
2013-07-05 16:04:06 +00:00
* @ return bool
*/
2013-07-09 18:34:12 +00:00
/*abstract*/ function insertUpdate ( $table , $rows , $primary ) {
2013-07-05 16:04:06 +00:00
return false ;
}
2013-07-09 18:43:01 +00:00
/** Begin transaction
* @ return bool
*/
function begin () {
return queries ( " BEGIN " );
}
2018-01-31 16:28:12 +00:00
/** Commit transaction
* @ return bool
*/
2013-07-09 18:43:01 +00:00
function commit () {
return queries ( " COMMIT " );
}
2018-01-31 16:28:12 +00:00
/** Rollback transaction
* @ return bool
*/
2013-07-09 18:43:01 +00:00
function rollback () {
return queries ( " ROLLBACK " );
}
2018-01-31 16:28:12 +00:00
/** Get warnings about the last command
* @ return resource or false
*/
function warnings () {
return false ;
}
2013-07-05 16:04:06 +00:00
}