<?php

namespace Linksy\SearchAndReplace\Plugli\Standard\Helpers\Database;

/**
 * The Database.
 *
 * @since      1.0.0
 * @package    Linksy
 * @subpackage Linksy\Helpers\Database
 * @author     Linksy <laxusgooee@gmail.com>
 */
/**
 * Database class.
 */
class Database
{
    /**
     * Array of all databases objects.
     *
     * @var array
     */
    protected static $instances = [];
    /**
     * Retrieve a Database instance by table name.
     *
     * @param string $table_name A Database instance id.
     *
     * @return QueryBuilder The current instance
     */
    public static function table($table_name)
    {
        global $wpdb;
        if (empty(self::$instances) || empty(self::$instances[$table_name])) {
            self::$instances[$table_name] = new QueryBuilder($wpdb->prefix . $table_name);
        }
        return self::$instances[$table_name];
    }
    public static function table_exists($table_name)
    {
        global $wpdb;
        $table_name = $wpdb->prefix . $table_name;
        return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name)) === $table_name;
    }
}
