LoginSignup
0
0

More than 3 years have passed since last update.

webarenaでubuntu その55

Last updated at Posted at 2019-10-04

概要

webarenaでubuntu18.04やってみた。
練習問題やってみた。

練習問題

いいねボタンを設置せよ。

写真

image.png

サンプルコード

<?php
    header("Access-Control-Allow-Origin: *");
    header("Content-Type:  application/json");
    $id = "test";
    $db = new PDO("mysql:host=localhost;dbname=mydb;", 'user', 'pass');
    if (!$db)
    {
        print "connect error!! <br>";
    }
    else
    {
        $sql = "SELECT * FROM counter WHERE id='$id'";
        $rs = $db->query($sql);
        if (!$rs)
        {
            print "Error in database!! 0 <br>";
            print $sql;
        }
        else
        {
            $userData = array();
            while ($row = $rs->fetch())
            {
                $userData[] = array('count' => $row['cnt']);
            }
            echo json_encode($userData);
        }
    }
?>

成果物

以上。

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