function __construct() { $this->db_host = get_db_host(); $this->db_name = get_db_name(); $this->db_username = get_db_username(); $this->db_password = get_db_password(); $this->db_object = new mysqli($this->db_host, $this->db_username, $this->db_password, $this->db_name); if ($this->db_object->connect_errno) { throw new DBConnectionException("MySQL Connection Error: " . $this->db_object->connect_error); } else { $this->db_connected = TRUE; } }
function get_table_names() { global $wpdb; $returnArray; $i = 0; $db_name = get_db_name(); $tables = $wpdb->get_results("SHOW TABLES IN {$db_name}"); foreach ($tables as $table) { $table = get_object_vars($table); //Convert stdClass to array $returnArray[$i++] = array_values($table)[0]; //Get the table name from the array } return $returnArray; }
function import_sql_scripts_to_databases($schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash) { foreach ($db_ids as $db_id) { if (get_db_type($db_id) != "mysql") { print "FIXME: database type " . get_db_type($db_id) . " is not supported.\n"; exit(1); } foreach ($schema_files as $schema_filename => $schema_db_id) { if ($schema_db_id == $db_id) { mysql_db_connect(get_db_address($db_id), get_db_login($db_id), get_db_password($db_id), get_db_name($db_id)); $sql = modify_content($schema_filename, array_merge($psa_modify_hash, $db_modify_hash, $settings_modify_hash, $settings_enum_modify_hash, $crypt_settings_modify_hash, $additional_modify_hash)); populate_mysql_db($sql); } } } }
function generate_options_page() { global $local, $custom, $script, $style, $wpdb; $db_name = get_db_name(); full_enqueue($custom, $script, 'jquery', "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"); full_enqueue($local, $script, 'block-ui', 'jquery-plugins/jquery.blockUI.js'); full_enqueue($local, $style, 'dbm-admin-style', 'style.css'); $ajaxData = ['ajax_url' => admin_url('admin-ajax.php'), 'wpdp_prefix' => $wpdb->prefix, 'wpdb_name' => $db_name, 'wpdb_tables' => get_table_names()]; localizeScript($local, 'dbm-admin-script', 'client-functions.js', 'ajax_obj', $ajaxData); //full_enqueue($local, $script, 'dbm-admin-script', 'client-functions.js'); echo generate_top_menu(); echo generate_input_area(); echo generate_table_list_container($db_name, get_table_names()); // echo $db_name . "<br>"; // $table_names = get_table_names(); // foreach($table_names as $handle) // { // echo '"' . $handle . '"' . "<br>"; // } }
/** Get PDO from the loaded database core module */ public static function getPDO($uid = null) { // Set uid to logged user if ($uid === null) { $uid = get_user_id(); } // Return cached pdo if same uid if (PDOBuilder::$pdo !== null && $uid === PDOBuilder::$pdoUid) { return PDOBuilder::$pdo; } $dsn = null; switch (get_db_type($uid)) { case 'mysql': $dsn = "mysql:dbname=" . get_db_name($uid) . ";host=" . get_db_host($uid) . ";port=" . get_db_port($uid); $options = array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''); $attributes = array(\PDO::ATTR_CASE => \PDO::CASE_UPPER); break; case 'postgresql': $dsn = "pgsql:dbname=" . get_db_name($uid) . ";host=" . get_db_host($uid) . ";port=" . get_db_port($uid); $options = array(); $attributes = array(\PDO::ATTR_CASE => \PDO::CASE_UPPER); break; default: die("Config error"); } try { PDOBuilder::$pdo = new \PDO($dsn, get_db_user($uid), get_db_password($uid), $options); foreach ($attributes as $key => $value) { PDOBuilder::$pdo->setAttribute($key, $value); } PDOBuilder::$pdoUid = $uid; return PDOBuilder::$pdo; } catch (\PDOException $e) { die("Connexion error " . $e); } }
public function get_keys() { $conn = connection(); $query = "SELECT getPKColumns('" . get_db_name() . "','" . get_class($this) . "')"; $k = mysqli_query($conn, $query); $retArray = array(); while ($r = mysqli_fetch_array($k)) { array_push($retArray, $r); } close($conn); return $retArray; }
function get_db_modify_hash($db_ids) { $parameters = array(); foreach ($db_ids as $db_id) { $parameters["@@" . "DB_" . strtoupper($db_id) . "_TYPE" . "@@"] = get_db_type($db_id); $parameters["@@" . "DB_" . strtoupper($db_id) . "_NAME" . "@@"] = get_db_name($db_id); $parameters["@@" . "DB_" . strtoupper($db_id) . "_LOGIN" . "@@"] = get_db_login($db_id); $parameters["@@" . "DB_" . strtoupper($db_id) . "_PASSWORD" . "@@"] = get_db_password($db_id); $parameters["@@" . "DB_" . strtoupper($db_id) . "_HOST" . "@@"] = fetch_env_var("DB_{$db_id}_HOST"); $parameters["@@" . "DB_" . strtoupper($db_id) . "_VERSION" . "@@"] = fetch_env_var("DB_{$db_id}_VERSION"); $parameters["@@" . "DB_" . strtoupper($db_id) . "_PORT" . "@@"] = fetch_env_var("DB_{$db_id}_PORT"); $parameters["@@" . "DB_" . strtoupper($db_id) . "_PREFIX" . "@@"] = get_db_prefix($db_id); $parameters["@@" . "DB_" . strtoupper($db_id) . "_ADDRESS" . "@@"] = get_db_address($db_id); } return $parameters; }