Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (27 sloc) 1.26 KB
# By Sharon Campbell for Heptio
# this is a pretty standard MySQL connection script using pdo_mysql
# we use environment variables for our MySQL connection
# the env variables are MYSQL_HOST, MYSQL_USER, and MYSQL_PASSWORD
# in our example MYSQL_HOST is mysql.default.svc.cluster.local
# MYSQL_USER is varMyDBUser and MYSQL_PASSWORD is varMyDBPass
# these env variables are set for our PHP server by Kubernetes when we create the php.yaml file
# the sensitive data itself is set in a Kubernetes Secret when we create the secrets.yaml file
# we are using the Sakila sample database
$mysql_host = getenv('MYSQL_HOST');
$dbh = new pdo( "mysql:host=$mysql_host:3306;dbname=sakila",
$result = $dbh->query("show tables");
while ($row = $result->fetch(PDO::FETCH_NUM)) {
echo($row[0]) . "<br />";
die(json_encode(array('outcome' => true)));
catch(PDOException $ex){
die(json_encode(array('outcome' => false, 'message' => "Unable to connect: $ex")));