Connect to coding sql database

Just a backup for coding connect to mysql datebase for myself.

index.php

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
<!DOCTYPE html>
<html>
<body>

<?php
$mysqli = new mysqli($_ENV['MYSQL_HOST'] . ":" . $_ENV['MYSQL_PORT'],$_ENV['MYSQL_USERNAME'],$_ENV['MYSQL_PASSWORD'],$_ENV['MYSQL_DBNAME']);

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

/* prepare statement */
if ($stmt = $mysqli->prepare("select id,title from dbtest")) {
$stmt->execute();

/* bind variables to prepared statement */
$stmt->bind_result($col1, $col2);

/* fetch values */
while ($stmt->fetch()) {
printf("%s %s\n", $col1, $col2);
}

/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();

?>

</body>
</html>