-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
42 lines (33 loc) · 1.06 KB
/
test.php
File metadata and controls
42 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
function placeholders($text, $count=0, $separator=","){
$result = array();
if($count > 0){
for($x=0; $x<$count; $x++){
$result[] = $text;
}
}
return implode($separator, $result);
}
$pdo = new PDO(
'mysql:host=localhost;dbname=gac',
'gac',
'x6QEX<7"f~5-');
$datafields = array('fielda', 'fieldb' );
$data[] = array('fielda' => 'value', 'fieldb' => 'value1' );
$data[] = array('fielda' => 'value', 'fieldb' => 'value1' );
$pdo->beginTransaction(); // also helps speed up your inserts.
$insert_values = array();
foreach($data as $d){
$question_marks[] = '(' . placeholders('?', sizeof($d)) . ')';
$insert_values = array_merge($insert_values, array_values($d));
}
$sql = "INSERT INTO table (" . implode(",", $datafields ) . ") VALUES " .
implode(',', $question_marks);
var_dump($insert_values);die;
$stmt = $pdo->prepare($insert_values);
try {
$stmt->execute($insert_values);
} catch (PDOException $e){
echo $e->getMessage();
}
$pdo->commit();