【发布时间】:2018-10-24 17:14:19
【问题描述】:
我能找到的唯一教程使用了不熟悉的替代资源,例如应用引擎、作曲家、github、代理和其他插件。
难道不能用纯 PHP 简单地连接它吗?
例如,我是否需要修改以下代码才能从 Google Cloud SQL 获取数据?
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
【问题讨论】:
-
如果您考虑“应用引擎、作曲家、github、代理、其他插件”,您可能不想使用 google-cloud。要成为“不熟悉的替代资源”,有很多替代品可能更适合您的速度
标签: php mysql google-cloud-platform cloud google-cloud-sql