· 7 years ago · Oct 09, 2018, 09:26 PM
1<?php
2
3$mysqli = new Mysqli('localhost', 'developer', 'developer', 'test');
4$mysqli->query('DROP TABLE IF EXISTS `test_artist`');
5$x = $mysqli->query('
6 CREATE TEMPORARY TABLE IF NOT EXISTS `test_artist` (
7 `id` int(11) NOT NULL AUTO_INCREMENT,
8 `name` varchar(255) NOT NULL,
9 `history` text,
10 PRIMARY KEY (`id`)
11 )
12');
13
14foreach (array(
15 array(
16 'id' => 1,
17 'name' => 'Kevin Schroeder',
18 'history' => 'Not his dayjob',
19 ),
20 array(
21 'id' => 2,
22 'name' => 'Linkin Park',
23 'history' => 'Was it rap, or rock?',
24 ),
25 array(
26 'id' => 3,
27 'name' => 'Lady Gaga',
28 'history' => 'mmmm tasty',
29 ),
30 array(
31 'id' => 4,
32 'name' => 'Britney Spears',
33 'history' => '199-what?',
34 ),
35 array(
36 'id' => 5,
37 'name' => 'ABBA',
38 'history' => 'who?',
39 )
40 )
41 as $data) {
42 $sql = 'INSERT INTO `test_artist` (`' . implode('`, `', array_keys($data)) . '`) VALUES (\'' . implode('\', \'', array_values($data)) . '\');';
43 $x = $mysqli->query($sql);
44 echo $mysqli->error;
45}
46
47
48$s = $mysqli->prepare('SELECT * FROM `test_artist`');
49$s->execute();
50$s->store_result(); // this does nothing
51
52$result = array(null, null, null);
53
54$s->bind_result($result[0], $result[1], $result[2]);
55
56while ($s->fetch()) {
57 var_dump($result);
58}
59
60// these do nothing?
61$s->reset();
62$s->data_seek(0);
63
64// how does one make this work?
65while ($s->fetch()) {
66 var_dump($result);
67}