@@ -26,7 +26,7 @@ $ mysql-ctl stop
26
26
$ mysql-ctl cli
27
27
```
28
28
29
- You can then connect to the database with following parameters:
29
+ After having started (and with that created) the database, you can connect to it using the following parameters:
30
30
<div markdown =" 1 " >
31
31
<table class =" table table-striped table-bordered " >
32
32
<thead>
@@ -40,7 +40,7 @@ You can then connect to the database with following parameters:
40
40
<tr>
41
41
<td>`Hostname`</td>
42
42
<td>`$IP`</td>
43
- <td>The same local IP as the application you run on Cloud9 </td>
43
+ <td>The environment variable 'IP' (type in a terminal: echo $IP) </td>
44
44
</tr>
45
45
<tr>
46
46
<td>`Port`</td>
@@ -50,12 +50,12 @@ You can then connect to the database with following parameters:
50
50
<tr>
51
51
<td>`User`</td>
52
52
<td>`$C9_USER`</td>
53
- <td>Your Cloud9 user name</td>
53
+ <td>Your Cloud9 user name (again an environment variable) </td>
54
54
</tr>
55
55
<tr>
56
56
<td>`Password`</td>
57
- <td>- </td>
58
- <td>No password since you can only access the DB from within the workspace</td>
57
+ <td>`<empty>` </td>
58
+ <td>No password (empty string); access is restricted to the the workspace</td>
59
59
</tr>
60
60
<tr>
61
61
<td>`Database`</td>
@@ -80,6 +80,86 @@ You are now in the MySQL environment and can start the import:
80
80
To verify that everything got imported run:
81
81
82
82
mysql> show tables;
83
+
84
+ Some useful CLI commands (please note the semicolon at the end of most of them):
85
+ <div markdown =" 1 " >
86
+ <table class =" table table-striped table-bordered " >
87
+ <thead>
88
+ <tr>
89
+ <th>Command</td>
90
+ <th>Description</td>
91
+ </tr>
92
+ </thead>
93
+ <tbody>
94
+ <tr>
95
+ <td>`help`</td>
96
+ <td>`list all mysql commands`</td>
97
+ </tr>
98
+ <tr>
99
+ <td>`show databases;`</td>
100
+ <td>`list the available databases`</td>
101
+ </tr>
102
+ <tr>
103
+ <td>`use c9`</td>
104
+ <td>`select/use database c9`</td>
105
+ </tr>
106
+ <tr>
107
+ <td>`show tables;`</td>
108
+ <td>`list the tables of the current database`</td>
109
+ </tr>
110
+ <tr>
111
+ <td>`exit`</td>
112
+ <td>`close the mysql command line tool`</td>
113
+ </tr>
114
+ <tr>
115
+ <td>`select * from mysql.user;`</td>
116
+ <td>`show all records/columns from system table user`</td>
117
+ </tr>
118
+ </tbody>
119
+ </table >
120
+ </div >
121
+
122
+ ## Connecting from PHP
123
+
124
+ So now you know how to create a database, start the db server, access it via a
125
+ command line tool.. It is time for the real deal: accessing it from your code.
126
+
127
+ In this example we will connect from PHP:
128
+
129
+ 1 . Create a new file, call it ` connect.php `
130
+
131
+ 2 . Copy/paste the following code in there:
132
+ ``` bash
133
+ < ? php
134
+ // A simple PHP script demonstrating how to connect to MySQL.
135
+ // Press the ' Run' button on the top to start the web server,
136
+ // then click the URL that is emitted to the Output tab of the console.
137
+
138
+ $servername = getenv(' IP' );
139
+ $username = getenv(' C9_USER' );
140
+ $password = " " ;
141
+ $database = " c9" ;
142
+ $dbport = 3306;
143
+
144
+ // Create connection
145
+ $db = new mysqli($servername , $username , $password , $database , $dbport );
146
+
147
+ // Check connection
148
+ if ($db -> connect_error) {
149
+ die(" Connection failed: " . $db -> connect_error);
150
+ }
151
+ echo " Connected successfully (" .$db -> host_info." )" ;
152
+ ? >
153
+ ` ` `
154
+
155
+ 3. Run the code by a right-click on the file tab ' connect.php' , select 'run this file'
156
+
157
+ 4. The output pane shows ' Starting Apache httpd...'
158
+
159
+ 5. Click the link that is displayed after that
160
+
161
+ 6. A preview pane will open, showing ' Connected successfully' .
162
+
83
163
84
164
Note:
85
165
MySQL socket file can be found in ~/lib/mysql/socket/mysql.sock
0 commit comments