Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cloud_sql/sqlserver/pdo/src/Votes.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function insertVote(string $value): bool
$res = false;

# [START cloud_sql_server_pdo_connection]
# [START cloud_sql_sqlserver_pdo_connection]
// Use prepared statements to guard against SQL injection.
$sql = "INSERT INTO votes (time_cast, vote_value) VALUES (GETDATE(), :voteValue)";

Expand All @@ -126,6 +127,7 @@ public function insertVote(string $value): bool
$e
);
}
# [END cloud_sql_sqlserver_pdo_connection]
# [END cloud_sql_server_pdo_connection]

return $res;
Expand Down
4 changes: 3 additions & 1 deletion cloud_sql/sqlserver/pdo/src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@

// Connect to the database.
# [START cloud_sql_server_pdo_timeout]
# [START cloud_sql_sqlserver_pdo_timeout]
// Here we set the connection timeout to five seconds and ask PDO to
// throw an exception if any errors occur.
$conn = new PDO($dsn, $username, $password, [
PDO::ATTR_TIMEOUT => 5,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
# [END cloud_sql_sqlserver_pdo_timeout]
# [END cloud_sql_server_pdo_timeout]
# [END cloud_sql_server_pdo_create_tcp]
# [END cloud_sql_sqlserver_pdo_create_tcp]
} catch (TypeError $e) {
throw new RuntimeException(
sprintf(
Expand Down