public function query($q, $params = array()){
		try{
			if(!empty($this->pdo)){
				$this->st = $this->pdo->prepare($q);
				if(!empty($params)){
					$keys = array_keys($params);
					$qmark = false;//qmark = question mark
					if(is_int($keys[0])){//mode '?'
						$qmark = true;
					}

					foreach($params as $p => $val){
						if($qmark){
							//$p is a numeric - 0, 1, 2, ...
							$p += 1;//bindValue starts to 1
						}
						if(is_array($val) && count($val) == 2){//if called with PDO::PARAM_STR or PDO::PARAM_INT, PDO::PARAM_BOOL
							$this->st->bindValue($p, $val[0], $val[1]);
						}
						else{
							if(! is_bool($val)) { //fix fatal error with some php versions
								$this->st->bindValue($p, $val);
							}
							else {
								$this->st->bindValue($p, $val, PDO::PARAM_INT);//cast
							}
						}
					}
				}

				$this->st->execute();
				return $this->st;
			}
			else{
				throw new DBException('PDO attribute is undefined');
			}
		}
		catch(\Exception $e){
			throw new DBException($e->getMessage(), $e->getCode());
		}
	}
public function query($q, $params = array()){
		try{
			if(!empty($this->pdo)){
				$this->st = $this->pdo->prepare($q);
				if(!empty($params)){
					$keys = array_keys($params);
					$qmark = false;//qmark = question mark
					if(is_int($keys[0])){//mode '?'
						$qmark = true;
					}

					foreach($params as $p => $val){
						if($qmark){
							//$p is a numeric - 0, 1, 2, ...
							$p += 1;//bindValue starts to 1
						}
						if(is_array($val) && count($val) == 2){//if called with PDO::PARAM_STR or PDO::PARAM_INT, PDO::PARAM_BOOL
							$this->st->bindValue($p, $val[0], $val[1]);
						}
						else{
							if(! is_bool($val)) { //fix fatal error with some php versions
								$this->st->bindValue($p, $val);
							}
							else {
								$this->st->bindValue($p, $val, PDO::PARAM_INT);//cast
							}
						}
					}
				}

				$this->st->execute();
				return $this->st;
			}
			else{
				throw new DBException('PDO attribute is undefined');
			}
		}
		catch(\Exception $e){
			throw new DBException($e->getMessage(), $e->getCode());
		}
	}
public function query ( $ q , $ params = array ( ) ) { try { if ( ! empty ( $ this -> pdo ) ) { $ this -> st = $ this -> pdo -> prepare ( $ q ) ; if ( ! empty ( $ params ) ) { $ keys = array_keys ( $ params ) ; $ qmark = false ; //qmark = question mark if ( is_int ( $ keys [ 0 ] ) ) { //mode '?' $ qmark = true ; } foreach ( $ params as $ p => $ val ) { if ( $ qmark ) { //$p is a numeric - 0, 1, 2, ... $ p += 1 ; //bindValue starts to 1 } if ( is_array ( $ val ) && count ( $ val ) == 2 ) { //if called with PDO::PARAM_STR or PDO::PARAM_INT, PDO::PARAM_BOOL $ this -> st -> bindValue ( $ p , $ val [ 0 ] , $ val [ 1 ] ) ; } else { if ( ! is_bool ( $ val ) ) { //fix fatal error with some php versions $ this -> st -> bindValue ( $ p , $ val ) ; } else { $ this -> st -> bindValue ( $ p , $ val , PDO :: PARAM_INT ) ; //cast } } } } $ this -> st -> execute ( ) ; return $ this -> st ; } else { throw new DBException ( 'PDO attribute is undefined' ) ; } } catch ( \ Exception $ e ) { throw new DBException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
execute a SQL query with params
execute a SQL query with params