# give/4.16.9/src/Framework/QueryBuilder/Concerns/InsertInto.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 56 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/QueryBuilder/Concerns/InsertInto.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Framework/QueryBuilder/Concerns/InsertInto.php
- Modified: 2025-03-31T19:17:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/Framework/QueryBuilder/Concerns/InsertInto.php#L10-L20`.

```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);
    }

}

```
