HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/give/src/Framework/QueryBuilder/Concerns/InsertInto.php
<?php

namespace Give\Framework\QueryBuilder\Concerns;

use Give\Framework\Database\DB;

/**
 * @since 4.0.0
 */
trait InsertInto
{
    /**
     * @since 4.0.0
     */
    public function getInsertIntoSQL($data, $format): string
    {
        $sql = 'INSERT INTO ' . $this->getTable()
               . sprintf(' (%s) ', implode(',', array_keys($data[0])))
               . 'VALUES ';

        foreach ($data as $row) {
            $sql .= DB::prepare(
                sprintf('(%s),', implode(',', $format ?? $this->getInsertIntoRowValuesFormat($row))),
                $row
            );
        }

        return rtrim($sql, ',');
    }

    /**
     * Get values format used by DB::prepare()
     *
     * @since 4.0.0
     *
     * @param array $data
     *
     * @return array
     */
    private function getInsertIntoRowValuesFormat(array $data): array
    {
        return array_map(function ($value) {
            if (is_int($value)) {
                return '%d';
            }

            if (is_float($value)) {
                return '%f';
            }

            return '%s';
        }, $data);
    }

}