code high light TEST

2019-01-18 14:57:28

PHP

<?php
// 資料來源名稱 (Data Source Name, DSN)
$dsn = 'mysql:host=localhost; dbname=test_db; charset=utf8';
$db_username = 'root';
$db_password = '';

// 連結資料庫
try {
    $pdo = new PDO($dsn, $db_username, $db_password);
    // 設定錯誤模式
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // PHP local 端模擬 prepare 的行為
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    // $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
} catch (PDOException $e) {
    // 設定資料庫出錯時丟出列外
    print "<h1>Couldn't connect to the database: <br>" . $e->getMessage() . "</h1>";
}
?>

SQL

        // articles(table) 新增標題及內文,並取得這筆資料的 id
    $sql = "INSERT INTO articles(title, content, draft)VALUES(?, ?, ?)";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([$title, $content, $draft]);
    $id = $pdo->lastInsertId();

    for ($i=0; $i < count($category_arr) ; $i++) {
        // taxonomy(table) 直接新增新的資料 (文章 id, 分類 id)
        $sqlInsert = "INSERT INTO taxonomy(article_id, category_id)VALUES(?, ?)";
        $stmtInsert = $pdo->prepare($sqlInsert);
        $stmtInsert->execute([$id, $category_arr[$i]]);
    }

    header('location: ./admin.php');

PHP

<?php
// 資料來源名稱 (Data Source Name, DSN)
$dsn = 'mysql:host=localhost; dbname=test_db; charset=utf8';
$db_username = 'root';
$db_password = '';

// 連結資料庫
try {
    $pdo = new PDO($dsn, $db_username, $db_password);
    // 設定錯誤模式
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // PHP local 端模擬 prepare 的行為
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    // $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
} catch (PDOException $e) {
    // 設定資料庫出錯時丟出列外
    print "<h1>Couldn't connect to the database: <br>" . $e->getMessage() . "</h1>";
}
?>

JavaScript

<html>
<head>
    <title>Functions!!!</title>
    <script type="text/javascript">
      function myFunction()
      {
        document.write("This is a simple function.<br />");
      }
        myFunction();
    </script>
</head>
<body>
</body>
</html> 
<!DOCTYPE html>
<html lang="zh-Hant-TW">
    <?php 
        $web_title = 'Login & Register « enter3017sky Blog';
        include_once './inc/head.php'; 
    ?>
<body>
<?php include './inc/navbar.php' ?>
    <div class="container">
    <header class="jumbotron text-center bg-white">
        <h1>Login & Sign up</h1>
    </header>
test
2019-01-19 20:51:46

12312

test
2019-01-19 20:51:53

321

12e12e21e
2019-01-21 00:12:19

12e12e21

12e12e
2019-01-21 00:12:51

12e1e12e

123
2019-01-21 00:13:27

321

123
2019-01-21 00:13:52

12313

a
2019-03-28 17:39:59

a

123
2019-04-03 20:14:46

321