Here's my current code:
$link = mysqli_connect("localhost", "username", "password", "database");
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$query = "SELECT id, title FROM titles WHERE type = 'movie' ORDER BY id ASC";
if ($result = mysqli_query($link, $query)) {
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s-%s
", $row["id"], $row["title"]);
}
mysqli_free_result($result);
}
mysqli_close($link);
Using printf
is correctly printing all the rows from my MySQL table.
However, instead of printing it, I want to write it to a text file. Is this possible to do with printf
or should I be doing something else?