eZ Community » Blogs » Steven E. Bailey » Using php to pass database values to...

By

Using php to pass database values to a bash shell

Friday 01 July 2011 11:55:46 pm

  • Currently 3 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Here's code that I've used in a bunch of places - especially for automated syncing scripts:

You have to run this from the ez root directory.

#!/bin/bash
getinidbinfo ()
{
dbinfo=`php -r "require 'autoload.php';
\\$script = eZScript::instance( array( 'debug-message' => '', 'use-session' => true, 'use-modules' => true, 'use-extensions' => true ) );
\\$script->startup();
\\$script->setUseSiteAccess( '${1}' );
\\$script->initialize();
\\$ini = eZINI::instance();
\\$database=\\$ini->variable( 'DatabaseSettings', 'Database' );
\\$user=\\$ini->variable( 'DatabaseSettings', 'User' );
\\$password=\\$ini->variable( 'DatabaseSettings', 'Password' );
\\$script->shutdown();
echo \\$database.':'.\\$user.':'.\\$password;"`
remote_db=${remote_db:-`echo $dbinfo|cut -f1 -d":"`}
remote_db_user=${remote_db_user:-`echo $dbinfo|cut -f2 -d":"`}
remote_db_passwd=${remote_db_passwd:-`echo $dbinfo|cut -f3 -d":"`}
}
getinidbinfo $*
echo $remote_db $remote_db_user $remote_db_passwd
Proudly Developed with from