Help us understand the problem. What is going on with this article?

Cloud9でDB接続(PHP)

More than 3 years have passed since last update.

Cloud9でPHP開発をするにあたって、
はじめの一歩となるDB接続について
良い記事がなかったためメモ

結論から言うと、connect.phpに以下のコードを張り付ければ良い

    <?php
        $servername = "127.0.0.1";
        $username = "username";
        $password = "";
        $database = "databasename";
        $dbport = 3306;

        // Create connection
        $db = new mysqli($servername, $username, $password, $database, $dbport);

        // Check connection
        if ($db->connect_error) {
            die("Connection failed: " . $db->connect_error);
        } 
        echo "Connected successfully (".$db->host_info.")";
    ?>

以下の部分は環境に応じて変更する。
・IP おそらく127.0.0.1
・C9_USER Cloud9で利用しているユーザー名
・password 初期値は無しで設定されているため、""
・database 作成したデータベース名。
・ポート番号 3306で指定

<<<<<<< HEAD
$servername = "127.0.0.1";

$username = "username";

        $servername = getenv('IP');
        $username = getenv('C9_USER');
>>>>>>> EDIT_REQUEST
        $password = "";
        $database = "databasename";
        $dbport = 3306;
<<<<<<< HEAD
=======

とても簡単ですね。

EDIT_REQUEST

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした