15
15
* limitations under the License.
16
16
*/
17
17
18
- # [START gae_cloudsql_connect ]
18
+ # [START gae_cloudsql_example ]
19
19
// Connect to CloudSQL from App Engine.
20
20
$ dsn = getenv ('CLOUDSQL_DSN ' );
21
21
$ user = getenv ('CLOUDSQL_USER ' );
22
22
$ password = getenv ('CLOUDSQL_PASSWORD ' );
23
23
if (!isset ($ dsn , $ user ) || false === $ password ) {
24
24
throw new Exception ('Set CLOUDSQL_DSN, CLOUDSQL_USER, and CLOUDSQL_PASSWORD environment variables ' );
25
25
}
26
- # [END gae_cloudsql_connect]
27
26
28
- # [START gae_cloudsql_create_tables]
29
27
// Create the PDO object to talk to CloudSQL
30
28
$ db = new PDO ($ dsn , $ user , $ password );
31
29
34
32
. 'guestName VARCHAR(255), '
35
33
. 'content VARCHAR(255)) ' );
36
34
$ result = $ stmt ->execute ();
37
- # [END gae_cloudsql_create_tables]
38
35
39
36
if (false === $ result ) {
40
37
exit ("Error: " . $ stmt ->errorInfo ()[2 ]);
41
38
}
42
39
43
- # [START gae_cloudsql_insert]
44
40
// Insert a new row into the guestbook on POST
45
41
if ($ _SERVER ['REQUEST_METHOD ' ] == 'POST ' ) {
46
42
$ stmt = $ db ->prepare ('INSERT INTO entries (guestName, content) VALUES (:name, :content) ' );
52
48
print ("Error: " . $ stmt ->errorInfo ()[2 ]);
53
49
}
54
50
}
55
- # [END gae_cloudsql_insert]
56
51
57
- # [START gae_cloudsql_query]
58
52
// Show existing guestbook entries.
59
53
$ results = $ db ->query ('SELECT * from entries ' );
60
- # [END gae_cloudsql_query]
61
54
62
55
?>
63
- # [START gae_cloudsql_results] ?>
56
+ ?>
64
57
65
58
66
59
if ($ results ->rowCount () > 0 ): ?>
78
71
79
72
80
73
81
- # [END gae_cloudsql_results] ?>
74
+ # [END gae_cloudsql_example] ?>
0 commit comments