0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

php v8 + MySQL v8 connection

Posted at

データベースの設定

image.png

ソースコード

index.php
<?php

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'php_dev');

$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if($conn->connect_error){
    die('Connection Failed ' . $conn->connect_error);
}

echo 'CONNECTED!';

$sql= 'SELECT * FROM feedback';
$result = mysqli_query($conn, $sql);
$feedback= mysqli_fetch_all($result, MYSQLI_ASSOC);

echo var_dump($feedback);

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<h1>Past Feedback</h1>
<?php if(empty($feedback)): ?>
<p>There is no feedback</p>
<?php endif; ?>
<?php foreach($feedback as $item):  ?>
<div>
    <div>
        <?php echo $item['body']; ?>
    </div>
    
    <div>
        <?php echo $item['name']; ?> on <?php echo $item['date']; ?>
    </div>
</div>
<?php endforeach; ?>

</body>
</html>

ブラウザ表示

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?