I am trying to get the prefix of multiple databases of wordpress installations with different prefixes. But failing to do this and is getting me only the first table prefix for all files:
Folder structure (basic - has all required wordpress files):
home:
+---cpanel1
| \---public_html
| +---wp-load.php => $table_prefix = 'wp1_';
+---cpanel2
| \---public_html
| +---wp-load.php => $table_prefix = 'wp2_';
\---cpanel3
\---public_html
+---wp-load.php => $table_prefix = 'wp3_';
+---get_prefixes.php
Script get_prefixes.php (PHP):
$myfile = '/wp-load.php';
class execute_sql_code {
public function __construct($myfile) {
$this->main_work($myfile);
}
public $cpanels = array(
'cpanel1',
'cpanel2',
'cpanel3'
);
public function main_work($myfile) {
foreach ($this->cpanels as $cpanel) {
$the_file = $cpanel.'/public_html'.$myfile;
var_dump($the_file);
require($the_file);
global $wpdb;
var_dump($wpdb->prefix);
}
}
}
new execute_sql_code($myfile);
var_dump($the_file) => OUTPUTS CORRECTLY every path.
var_dump($wpdb->prefix) => OUTPUTS WRONG wp1_ for each iteration:
CURRENT OUTPUT:
Iteration 1 => cpanel1/public_html/wp-load.php =>
$wpdb->prefix = wp1_Iteration 2 => cpanel2/public_html/wp-load.php =>
$wpdb->prefix = wp1_Iteration 3 => cpanel3/public_html/wp-load.php =>
$wpdb->prefix = wp1_
EXPECTED OUTPUT:
Iteration 1 => cpanel1/public_html/wp-load.php =>
$wpdb->prefix = wp1_Iteration 2 => cpanel2/public_html/wp-load.php =>
$wpdb->prefix = wp2_// normalIteration 3 => cpanel3/public_html/wp-load.php =>
$wpdb->prefix = wp3_// normal
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire