PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Framework / QueryBuilder / Concerns / InsertInto.php

InsertInto.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Framework/QueryBuilder/Concerns/InsertInto.php

56 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\QueryBuilder\Concerns;
4
5 use Give\Framework\Database\DB;
6
7 /**
8 * @since 4.0.0
9 */
10 trait InsertInto
11 {
12 /**
13 * @since 4.0.0
14 */
15 public function getInsertIntoSQL($data, $format): string
16 {
17 $sql = 'INSERT INTO ' . $this->getTable()
18 . sprintf(' (%s) ', implode(',', array_keys($data[0])))
19 . 'VALUES ';
20
21 foreach ($data as $row) {
22 $sql .= DB::prepare(
23 sprintf('(%s),', implode(',', $format ?? $this->getInsertIntoRowValuesFormat($row))),
24 $row
25 );
26 }
27
28 return rtrim($sql, ',');
29 }
30
31 /**
32 * Get values format used by DB::prepare()
33 *
34 * @since 4.0.0
35 *
36 * @param array $data
37 *
38 * @return array
39 */
40 private function getInsertIntoRowValuesFormat(array $data): array
41 {
42 return array_map(function ($value) {
43 if (is_int($value)) {
44 return '%d';
45 }
46
47 if (is_float($value)) {
48 return '%f';
49 }
50
51 return '%s';
52 }, $data);
53 }
54
55 }
56