04 Sessions Mysql 20 2.01 Pdo_01

04 Sessions Mysql20 2.01 Pdo_01

php.net | The PDOStatement class

A total of 8 records were found.

SELECT * 
FROM php_a04_images

Debug Code - var_dump($conn)


object(PDO)#1 (0) {
}

Debug Code - var_dump($conn->getAttribute())


PDO::ATTR_AUTOCOMMIT: 
1

PDO::ATTR_ERRMODE: 
2

PDO::ATTR_CASE: 
0

PDO::ATTR_CLIENT_VERSION: 
mysqlnd 8.1.30

PDO::ATTR_CONNECTION_STATUS: 
Localhost via UNIX socket

PDO::ATTR_EMULATE_PREPARES: 
1

PDO::ATTR_ORACLE_NULLS: 
0

PDO::ATTR_PERSISTENT: 


PDO::ATTR_SERVER_INFO: 
Uptime: 1921972  Threads: 13  Questions: 26738146  Slow queries: 0  Opens: 419483  Flush tables: 1  Open tables: 2000  Queries per second avg: 13.911

PDO::ATTR_SERVER_VERSION: 
10.3.39-MariaDB-0ubuntu0.20.04.2

Debug Code - $conn->errorInfo()


array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  NULL
  [2]=>
  NULL
}

Debug Code - var_dump($result)


object(PDOStatement)#2 (1) {
  ["queryString"]=>
  string(30) "SELECT * 
FROM php_a04_images
"
}
$_SERVER["SCRIPT_NAME"]
/php/assignments/04-sessions-mysql/20-2.01-pdo_01.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');

// 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>

    <p><a href="https://www.php.net/manual/en/class.pdostatement.php">php.net | The PDOStatement class</a></p>

    <?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><?= $sql ?></code></pre>
    </figure>

    <h2>Debug Code - var_dump($conn)</h2>
    <pre class="line-numbers">
<code class="language-php">
<?php var_dump($conn); ?>
</pre>
    </code>

    <h2>Debug Code - var_dump($conn->getAttribute())</h2>
    <pre class="line-numbers">
<code class="language-php">
<?php
$attributes 
= [
    
"AUTOCOMMIT",
    
"ERRMODE",
    
"CASE",
    
"CLIENT_VERSION",
    
"CONNECTION_STATUS",
    
"EMULATE_PREPARES",
    
"ORACLE_NULLS",
    
"PERSISTENT",
    
"SERVER_INFO",
    
"SERVER_VERSION"
];

foreach (
$attributes as $val) {
    echo 
"PDO::ATTR_$val: \n";
    echo 
$conn->getAttribute(constant("PDO::ATTR_{$val}")) . "\n\n";
}
?>
</pre>
    </code>

    <h2>Debug Code - $conn->errorInfo()</h2>
    <pre class="line-numbers">
<code class="language-php">
<?php var_dump($conn->errorInfo()); ?>
</pre>
    </code>

    <h2>Debug Code - var_dump($result)</h2>
    <pre class="line-numbers">
<code class="language-php">
<?php var_dump($result); ?>
</pre>
    </code>
</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");
?>