Skip to content

Instantly share code, notes, and snippets.

@drymek
Created October 14, 2013 12:45
Show Gist options
  • Save drymek/6975023 to your computer and use it in GitHub Desktop.
Save drymek/6975023 to your computer and use it in GitHub Desktop.
Open database manager (mysql is the only one supported right now) based on parameters.yml file.
#!/bin/bash
## Usage
## database.sh /path/parameters.yml
## or if you are in symfony root directory
## database.sh
if [ -z $1 ]
then
if [ -f "app/config/parameters.yml" ]
then
PARAMETERS="app/config/parameters.yml"
else
echo "Can not locate parameters.yml file"
fi
else
if [ -f $1 ]
then
PARAMETERS=$1
else
echo "Given parameters.yml path does not exists"
fi
fi
DRIVER=`cat $PARAMETERS | grep database_driver | awk '{print $2}'`
PASSWORD=`cat $PARAMETERS | grep database_password | awk '{print $2}'`
USER=`cat $PARAMETERS | grep database_user | awk '{print $2}'`
HOST=`cat $PARAMETERS | grep database_host | awk '{print $2}'`
PORT=`cat $PARAMETERS | grep database_port | awk '{print $2}'`
NAME=`cat $PARAMETERS | grep database_name | awk '{print $2}'`
if [ 'pdo_mysql' = $DRIVER ]
then
if [ 'null' = $PORT ]
then
PORT='3306'
fi
mysql -u$USER -p$PASSWORD -h$HOST -P$PORT $NAME
else
echo -e "Unknown driver $DRIVER"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment