05 AWS RDS
Read Replication
예제
db.php
1 2 3 | <?php $write = mysqli_connect( '' , '' , '' , 'o2' ); $read = mysqli_connect( '' , '' , '' , 'o2' ); |
rds.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <!DOCTYPE> <html> <head><meta charset= "utf-8" ></head> <body> <form action= "rds_receiver.php" method= "post" > <p> 제목 : <input type= "text" name= "title" > </p> <p> 본문 : <textarea name= "description" > </textarea> </p> <p><input type= "submit" ></p> </form> <ul> <?php include ( 'db.php' ); $result = mysqli_query( $read , "SELECT * FROM topic" ); while ( $row = mysqli_fetch_assoc( $result )){ $title = mysqli_real_escape_string( $read , $row [ 'title' ]); print ( "<li>{$title}</li>" ); } ?> </ul> </body> </html> |
rds_receiver.php
1 2 3 4 5 6 7 8 | <?php include ( 'db.php' ); $title = mysqli_real_escape_string( $write , $_POST [ 'title' ]); $description = mysqli_real_escape_string( $write , $_POST [ 'description' ]); $sql = "INSERT INTO topic (title, description, author, created) VALUES('{$title}', '{$description}', 'egoing', NOW())" ; mysqli_query( $write , $sql ); header( 'Location: rds.php' ); ?> |