04 Sessions Mysql 20 2.02 Pdo_02

04 Sessions Mysql20 2.02 Pdo_02

A total of 8 records were found.

SQL: [30] SELECT * 
FROM php_a04_images

Params:  0
ID filename caption
1 basin.jpg Water basin at Ryoanji temple, Kyoto.
2 fountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountains.jpg 🚀 Fountain's in central Tokyo
3 kinkakuji.jpg The Golden Pavilion in Kyoto
4 maiko.jpg Maiko—trainee geishas in Kyoto
5 maiko_phone.jpg Every maiko should have one—a mobile, of course
6 menu.jpg Menu outside restaurant in Pontocho, Kyoto
7 monk.jpg Monk begging for alms in Kyoto
8 ryoanji.jpg 🛕 Autumn leaves at Ryoanji temple, Kyoto

Animated GIF: foreach ($result as $row)

Animated GIF: $row = $result->fetch_assoc()

Debug Code - foreach ($result as $row)


Array
(
    [0] => Array
        (
            [image_id] => 1
            [0] => 1
            [filename] => basin.jpg
            [1] => basin.jpg
            [caption] => Water basin at Ryoanji temple, Kyoto.
            [2] => Water basin at Ryoanji temple, Kyoto.
        )

    [1] => Array
        (
            [image_id] => 2
            [0] => 2
            [filename] => fountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountains.jpg
            [1] => fountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountainsfountains.jpg
            [caption] => 🚀 Fountain's in central Tokyo
            [2] => 🚀 Fountain's in central Tokyo
        )

    [2] => Array
        (
            [image_id] => 3
            [0] => 3
            [filename] => kinkakuji.jpg
            [1] => kinkakuji.jpg
            [caption] => The Golden Pavilion in Kyoto
            [2] => The Golden Pavilion in Kyoto
        )

    [3] => Array
        (
            [image_id] => 4
            [0] => 4
            [filename] => maiko.jpg
            [1] => maiko.jpg
            [caption] => Maiko—trainee geishas in Kyoto
            [2] => Maiko—trainee geishas in Kyoto
        )

    [4] => Array
        (
            [image_id] => 5
            [0] => 5
            [filename] => maiko_phone.jpg
            [1] => maiko_phone.jpg
            [caption] => Every maiko should have one—a mobile, of course
            [2] => Every maiko should have one—a mobile, of course
        )

    [5] => Array
        (
            [image_id] => 6
            [0] => 6
            [filename] => menu.jpg
            [1] => menu.jpg
            [caption] => Menu outside restaurant in Pontocho, Kyoto
            [2] => Menu outside restaurant in Pontocho, Kyoto
        )

    [6] => Array
        (
            [image_id] => 7
            [0] => 7
            [filename] => monk.jpg
            [1] => monk.jpg
            [caption] => Monk begging for alms in Kyoto
            [2] => Monk begging for alms in Kyoto
        )

    [7] => Array
        (
            [image_id] => 8
            [0] => 8
            [filename] => ryoanji.jpg
            [1] => ryoanji.jpg
            [caption] => 🛕 Autumn leaves at Ryoanji temple, Kyoto
            [2] => 🛕 Autumn leaves at Ryoanji temple, Kyoto
        )

)
$debug_query_data[]: 1
$_SERVER["SCRIPT_NAME"]
/php/assignments/04-sessions-mysql/20-2.02-pdo_02.php

print_r($_GET)
Array
(
)


print_r($_POST)
Array
(
)


print_r($_SESSION)
Array
(
)


print_r($_FILES)
Array
(
)



<?php
// Database Connection
require_once('../../includes/connection.php');

// Utility Functions
require_once '../../includes/utility_funcs.php';

// Connect to Database Using MySQL
$conn dbConnect('read''pdo');

// Prepare the SQL query
$sql 'SELECT * 
FROM php_a04_images
'
;

// Submit the Query and Capture the Result
$result $conn->query($sql);

// Check for PHP Data Object (PDO) Errors
$error $conn->errorInfo()[2];

// Check For Database Errors
if (!$error) {
    
$numRows $result->rowCount();
}

$tools true;
include(
"../../includes/header.php");
?>

<main>
    <h2><?php echo $folder_name?><span><?php echo $file_name?></span></h2>

    <?php
    
if (isset($error)) {
        echo 
"<p class=\"error\">$error</p>";
    } else {
        echo 
"<p class=\"info\">A total of $numRows records were found.</p>";
    }
    
?>

    <figure class="code">
        <pre class="language-sql"><code><?= $result->debugDumpParams(); ?></code></pre>
    </figure>

    <table id="output-sql">
        <tr>
            <th>ID</th>
            <th>filename</th>
            <th>caption</th>
        </tr>
        <?php
        $debug_query_data 
= [];
        
?>
        <?php foreach ($result as $row) { ?>
            <tr>
                <td><?php echo $row['image_id']; ?></td>
                <td><?php echo safe($row['filename']); ?></td>
                <td><?php echo safe($row['caption']); ?></td>
            </tr>

            <?php
            
// Debug - Capture Each Row of Data
            
$debug_query_data[] = $row;

            
?>
        <?php ?>
    </table>

    <h2>Animated GIF: foreach ($result as $row)</h2>
    <p><img src="_assets/$row=$result->fetch_assoc().gif" alt="Animated GIF: $row = $result->fetch_assoc()"></p>

    <h2>Debug Code - foreach ($result as $row)</h2>
    <pre class="line-numbers">
<code class="language-php">
<?php if (isset($debug_query_data)) echo '$debug_query_data[]: ' print_r($debug_query_data); ?>
</code>
</pre>

</main>

<?php
# The side-bar section of the layout use custom path to load from a different folder.
include("../../includes/sidebar.php");

# The footer section of the layout.
include("../../includes/footer.php");
?>