-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqli_stmt.php
More file actions
46 lines (38 loc) · 1.13 KB
/
mysqli_stmt.php
File metadata and controls
46 lines (38 loc) · 1.13 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
43
44
45
46
<?php
/* open a connection */
$mysqli = new mysqli('localhost', 'phpdemo', 'phpdemo', 'world');
/* check connection */
if ($mysqli->connect_errno) {
die('Connect Error (' . $mysqli->connect_errno. ')' . $mysqli->connect_error);
}
$sql = "SELECT Name, CountryCode FROM City WHERE id < ?";
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("i", $id);
$id = 10;
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($name, $code);
/* store result */
$stmt->store_result();
printf("Numbers of rows: %d\n", $stmt->num_rows);
echo "<table border=1 align='center' width= 500>";
/* get resultset for metadata */
$result = $stmt->result_metadata();
/* retrieve field information from metadata result set */
while ($field = $result->fetch_field()) {
echo "<th>" . $field->name . "</th>";
}
$result->close();
while ($stmt->fetch()) {
printf("%s, (%s), $name, $code);
}
echo "</table>";
/* free result */
$stmt->free_result();
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>