Перестроить запрос и набор данных, если данные содержат значения в виде массиво

@param string $sql - текст SQL-запроса
@param array $data - массив данных для выполения запроса

@return array
435764
public static function createAllPostgresArrayPlaceholders(string &$sql, array &$data) : array
    {
        if (empty($data[0]) || !\is_array($data[0])) {
            $data = [$data];
        }

        foreach ($data as &$record) {
            foreach (array_keys($record) as &$key) {
                static::replacePostgresArray($sql, $record, $key);
            }

            unset($key);
        }

        unset($record);

        $data = \count($data) > 1 ? $data : reset($data);
        return [$sql, $data];
    }
1140795
public function get_sql_filter($data) {
        global $DB;
        static $counter = 0;
        $name = 'ex_cohort'.$counter++;

        $operator = $data['operator'];
        $value    = $data['value'];

        $params = array();

        if ($value === '') {
            return '';
        }

        $not = '';
        switch($operator) {
            case 0: // Contains.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value%";
                break;
            case 1: // Does not contain.
                $not = 'NOT';
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value%";
                break;
            case 2: // Equal to.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "$value";
                break;
            case 3: // Starts with.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "$value%";
                break;
            case 4: // Ends with.
                $res = $DB->sql_like('idnumber', ":$name", false, false);
                $params[$name] = "%$value";
                break;
            case 5: // Empty.
                $not = 'NOT';
                $res = '(idnumber IS NOT NULL AND idnumber <> :'.$name.')';
                $params[$name] = '';
                break;
            default:
                return '';
        }

        $sql = "id $not IN (SELECT userid
                         FROM {cohort_members}
                         JOIN {cohort} ON {cohort_members}.cohortid = {cohort}.id
                        WHERE $res)";

        return array($sql, $params);
    }
594547
public static function parseConditions(string &$sql, array &$data) : array
    {
        if (!preg_match_all(
            '/\[((?:AND|OR|NOT|AND NOT|OR NOT|WHERE)\s+[^:]+:[\w_\-]+.+?)\]/i',
            $sql,
            $matches,
            PREG_SET_ORDER
        )) {
            return [$sql, $data];
        }

        foreach ($matches as $match) {
            preg_match_all('/[^:]:([\w_\-]+)/', $sql, $args, PREG_SET_ORDER);

            foreach ($args as $m) {
                if (!array_key_exists($m[1], $data)) {
                    $sql = str_replace($match[0], '', $sql);
                    continue;
                }

                $sql = str_replace($match[0], $match[1], $sql);
            }
        }

        return [$sql, $data];
    }
1094458
public function replaceSiteDomainInSqlArray(array $sql)
    {
        if (empty($sql)) {
            return [];
        }

        $delimiter = md5(uniqid('delim', true));
        $joined = implode($delimiter, $sql);
        $replaced = $this->replaceSiteDomainInSqlString($joined);

        return explode($delimiter, $replaced);
    }
224242
public function fetch_objects($sql)
    {
        $result = $this->query($sql);
        $array  = null;
        while (true == ($row = mysql_fetch_object($result))) {
            $array[] = $row;
        }
        mysql_free_result($result);
        return $array;
    }
477613
protected function getSelectSql(array $sql): array
    {
        $sql[] = trim('SELECT ' . trim(implode(' ', [
            $this->distinct,
            $this->highPriority,
            $this->straightJoin,
            $this->resultSize,
            $this->bufferResult,
            $this->calcFoundRows,
        ])));

        return $sql;
    }
999074
protected function fetch($sql)
    {
        try {
            try {
                $stm = Connect::getConn()->prepare($sql);
            } catch (Exception $e) {
                static::$response["status"] = "error";
                static::$response["response"] = $e->getMessage();
                static::$response['code'] = $e->getCode();
               return static::terminate(static::$response);

            }
            try {
                $stm->execute();
            } catch (Exception $e) {
                static::$response["status"] = "error";
                static::$response["response"] = $e->getMessage();
                static::$response['code'] = $e->getCode();
               return static::terminate(static::$response);
            }
        } catch (Exception $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response['code'] = $e->getCode();
           return static::terminate(static::$response);

        }
        try {
            $data = null;
            // set the resulting array to associative
            $stm->setFetchMode(PDO::FETCH_ASSOC);
            foreach (new RecursiveArrayIterator($stm->fetchAll()) as $k => $v) {
                $data[] = $v;
            }

            if ($data == null) {
                static::$response["status"] = "success";
                static::$response["response"] = Null;
                static::$response['code'] = 300;
               return static::terminate(static::$response);
            }
            static::$response["status"] = "success";
            static::$response["response"] = $data;
            static::$response['code'] = 200;
            return static::terminate(static::$response);


        } catch (PDOException $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response["code"] = $e->getCode();
           return static::terminate(static::$response);
        }


    }
801765
public static function data($sql, $type = 'query') {
        self::init();
        self::deprecationWarning();
        return Deprecated::data($sql, $type);
    }
586252
public function query($sql, $data = [])
     {
         $this->_init();

         try {
             $q = $this->db->prepare($sql);
         } catch (PDOException $e) {
             throw new Exception($e->getMessage());
         }

         foreach ($data as $k => $v) {
             $$k = $v;
             $q->bindParam(':' . $k, $$k); # bindParam( ... , PDO::PARAM_INT ...);
         }

         $result = $q->execute();

         if (strpos(trim(strtoupper($sql)), 'SELECT') === 0) {
             $rows = [];
             while($row = $q->fetch()) {
                 $rows[] = $row;
             }
             return $rows;
         }

         return $result;
     }
166783
public function fetch_array($sql)
    {
        $rs   = $this->query($sql);
        $data = $rs->fetchArray(SQLITE3_ASSOC);
        $GLOBALS['__$DB_QUERY_COUNT']++;

        $rs->finalize();
        return $data;
    }
383003
public static function fetchAll($sql) {
		$return = array();
		$results = \Database::getInstance()->query($sql);
		while ($result = $results->fetchAssoc()) {
			$return[$result['id']] = $result;
		}
		return $return;
	}
19712
public static function format_sql( $sql ) {

		$sql = str_replace( array( "\r\n", "\r", "\n", "\t" ), ' ', $sql );
		$sql = esc_html( $sql );
		$sql = trim( $sql );

		$regex = 'ADD|AFTER|ALTER|AND|BEGIN|COMMIT|CREATE|DELETE|DESCRIBE|DO|DROP|ELSE|END|EXCEPT|EXPLAIN|FROM|GROUP|HAVING|INNER|INSERT|INTERSECT|LEFT|LIMIT|ON|OR|ORDER|OUTER|RENAME|REPLACE|RIGHT|ROLLBACK|SELECT|SET|SHOW|START|THEN|TRUNCATE|UNION|UPDATE|USE|USING|VALUES|WHEN|WHERE|XOR';
		$sql   = preg_replace( '# (' . $regex . ') #', '<br> $1 ', $sql );

		$keywords = '\b(?:ACTION|ADD|AFTER|ALTER|AND|ASC|AS|AUTO_INCREMENT|BEGIN|BETWEEN|BIGINT|BINARY|BIT|BLOB|BOOLEAN|BOOL|BREAK|BY|CASE|COLLATE|COLUMNS?|COMMIT|CONTINUE|CREATE|DATA(?:BASES?)?|DATE(?:TIME)?|DECIMAL|DECLARE|DEC|DEFAULT|DELAYED|DELETE|DESCRIBE|DESC|DISTINCT|DOUBLE|DO|DROP|DUPLICATE|ELSE|END|ENUM|EXCEPT|EXISTS|EXPLAIN|FIELDS|FLOAT|FOREIGN|FOR|FROM|FULL|FUNCTION|GROUP|HAVING|IF|IGNORE|INDEX|INNER|INSERT|INTEGER|INTERSECT|INTERVAL|INTO|INT|IN|IS|JOIN|KEYS?|LEFT|LIKE|LIMIT|LONG(?:BLOB|TEXT)|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|NOT|NO|NULLIF|ON|ORDER|OR|OUTER|PRIMARY|PROC(?:EDURE)?|REGEXP|RENAME|REPLACE|RIGHT|RLIKE|ROLLBACK|SCHEMA|SELECT|SET|SHOW|SMALLINT|START|TABLES?|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TRUNCATE|UNION|UNIQUE|UNSIGNED|UPDATE|USE|USING|VALUES?|VAR(?:BINARY|CHAR)|WHEN|WHERE|WHILE|XOR)\b';
		$sql      = preg_replace( '#' . $keywords . '#', '<b>$0</b>', $sql );

		return '<code>' . $sql . '</code>';

	}
1320280
public function parse_sql( $data = null ) {

		if ( ! empty( $data ) ) {
			$this->input = $data;
		}

		$this->parsed = $data;

		return $this->parsed;
	}
19912
public function get_sql( $sql ) {

		global $wpdb;

		if ( empty( $sql ) ) {
			$sql = $this->sql;
		}

		/**
		 * Allow SQL query to be manipulated.
		 *
		 * @param string   $sql       SQL Query string.
		 * @param PodsData $pods_data PodsData object.
		 *
		 * @since 2.7.0
		 */
		$sql = apply_filters( 'pods_data_get_sql', $sql, $this );

		$sql = str_replace( array( '@wp_users', '@wp_' ), array( $wpdb->users, $wpdb->prefix ), $sql );

		$sql = str_replace( '{prefix}', '@wp_', $sql );
		$sql = str_replace( '{/prefix/}', '{prefix}', $sql );

		return $sql;
	}
511260
public static function prepare( $sql, $data ) {

		/**
		 * @var $wpdb wpdb
		 */
		global $wpdb;
		list( $sql, $data ) = apply_filters( 'pods_data_prepare', array( $sql, $data ) );

		return $wpdb->prepare( $sql, $data );
	}
962744
public static function findOneBySql($sql,$data=[],$db_name=''){
		# example: $sql ='SELECT * FROM post WHERE id=1'
		$db = self::getDb($db_name);
		$result = $db->createCommand($sql,$data)
				->queryOne();
		return $result;
	}
860553
public static function execute($sql, $data = [])
    {
        $statement = self::$pdo->prepare($sql);
        $statement->execute($data);
        return $statement;
    }