본문 바로가기
💻CODING/php

[php] mysql, 데이터베이스 기초 예제 (ft. 테이블 불러오기)

by 코딩하는 갓디노 2023. 1. 20.

[php] mysql, 데이터베이스 기초 예제 (ft. 테이블 불러오기)

 

화면 결과

 

mysql 테이블

 

mysql 데이터

 

db 출력하기

<?php
$server_name = 'localhost:3307';
$user = 'root';
$password = '';
// $port = '3307';
$database = 'php';

$connect = mysqli_connect($server_name, $user, $password, $database);
mysqli_select_db($connect, $database) or die('db select failed');

$sql_query = 'select * from members order by age desc';
$result = mysqli_query($connect, $sql_query);

echo '<table border="1">';
echo '<tr>';
echo '<th>no</th>';
echo '<th>name</th>';
echo '<th>age</th>';
echo '<th>gender</th>';
echo '<th>registration date</th>';
echo '</tr>';

while($row = mysqli_fetch_array($result))
{
    echo '<tr>';
    echo '<td>'.$row['idx'].'</td>';
    echo '<td>'.$row['name'].'</td>';
    echo '<td>'.$row['age'].'</td>';
    echo '<td>'.$row['gender'].'</td>';
    echo '<td>'.$row['regdate'].'</td>';
    echo '</tr>';
}

echo '</table>';
mysqli_close($connect);
?>
반응형

댓글