• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Accessing to all accounts, domain names and databases from one single PHP script...

S

stephaneeybert

Guest
Dear all,

I have a server with several accounts, each having several domain names, each having one database.

All of these databases have the same structure. Only their content is different.

I would like to be able to access all these databases from one single PHP script, so as to make updates to all of them in one shot.

Today, I must do it manually, under Plesk, one by one, through the GUI. Painfull...

I had done this script in the past for a shared hosting server. Of course it does not work on a Plesk server.

How to access all accounts, domain names and database from a sinple PHP script..?

Here is the old script

<?PHP

include_once("website.php");
include_once($gAdminPath . "includes.php");
include_once($gLanguagePath . "includes.php");

// Check that the administrator is allowed to use the module
$adminUtils = new AdminUtils();
$adminUtils->checkForStaffLogin();

// Get the multi language form text strings
$languageUtils = new LanguageUtils();
$mlText = $languageUtils->getMlText(__FILE__);

// Process the data from the form
$formSubmitted = LibEnv::getEnvHttpPOST("formSubmitted");

$strResult = "";

if ($formSubmitted) {

// Get the variables
$statement = LibEnv::getEnvHttpPOST("statement");

// Strip the magic quote slashes
$statement = LibString::stripSlashMagicQuotes($statement);

$sqlToolsUtils = new SqlToolsUtils();
$dbNames = $sqlToolsUtils->getDatabaseNames();

$strResult = "<br>Database statement: <b>$statement</b><br><br>";

foreach ($dbNames as $dbName) {
$sqlToolsUtils = new SqlToolsUtils($dbName);

$str = "Database name: <b>$dbName</b><br>";
$strResult .= $str;

$sqlToolsUtils->performStatement($statement);

$errorMessage = $sqlToolsUtils->getErrorMessage();
if ($errorMessage) {
$strResult .= "<br>$errorMessage<br><br>";
}

// Release the data source
$sqlToolsUtils->freeDataSource();
}

}

$objLayout = new SysLayout();
$objLayout->setHeader($mlText[0], "$gAdminUrl/menu.php");
$objLayout->addLine("", $strResult);
$objLayout->addHidden("<form action='$PHP_SELF' method='post'>");
$objLayout->addLine(array($mlText[1], "b"), "<textarea id='statement' name='statement' cols='80' rows='4'></textarea>");
$objLayout->addLine();
$objLayout->addLine("", $objLayout->getOk());
$objLayout->addHidden("<input type='hidden' name='formSubmitted' value='1'>");
$objLayout->addHidden("</form>");
$str = $objLayout->render();

printAdminPage($str);

?>

<?

// This class is a utility class.
// It is an application specific interface to a database.

class SqlToolsDB {

var $dataSource;
var $dao;

// Get all database names
function getDatabaseNames() {
// Select the database
$this->dataSource->selectDatabase();

// Select the object
// If the sql statement is successful and a result is returned
$names = Array();
if ($result = $this->dao->getDatabaseNames()) {
// Then get the rows
for ($i = 0; $i < $result->getRowCount(); $i++) {
$row = $result->getRow($i);

$name = $row['Database'];
// DB_COMMON_DB_NAME is the name of the database common to and used by
// all the web sites, and DB_SYSTEM_DB_NAME is the name of the database used
// only by the RDBMS to manage user and table rights (mysql in MySql)
if ($name != DB_COMMON_DB_NAME && $name != DB_SYSTEM_DB_NAME) {
array_push($names, $name);
}
}
}

return($names);
}


}

?>

Kind Regards

Stephane
 
You have to connect to mysql as admin / <pleskadminpassword>

I'm to lazy to read your whole script but perhaps thats the problem
 
Back
Top