Returns random record from given table.
@param string $tableName
@return IRow|false
961012
protected function getRecord($tableName, $where = null)
    {
        $record = $this->database->table($tableName)->order('RAND()');
        return $where ?
            $record->where($where)->limit(1)->fetch() :
            $record->limit(1)->fetch();
    }
633053
public function getByUsername($username)
    {
        if (!is_string($username)) {
            return false;
        }

        $data = [
            'where' => [
                [
                    'column' => $this->tableAlias . '.username',
                    'value'  => $username,
                ],
            ],
        ];

        $user = $this->getAll(null, null, $data);

        return empty($user) ? false : $user[0];
    }
861734
public function select($tableName, $fields = ['*'])
    {
        $sql = new Select($tableName, $fields);
        $sql->setAdapter($this->_adapter);
        return $sql;
    }
297365
protected function tableExists($tableName)
    {
        $tables = $this->connection->getSchemaManager()->listTables();

        foreach ($tables as $table) {
            if ($table->getName() == $tableName) {
                return true;
            }
        }

        return false;
    }
649429
protected static function checkTableName($tableName, $con=NULL)
    {
        $connection = self::checkConnection($con);

        $query = $connection->query("SELECT 1 FROM {$tableName} LIMIT 1");
        if($query !== false)
        {
            return $tableName;
        }
        throw new TableDoesNotExistException();
    }
702607
protected function getTableSelects($tableName,$tableAlias = null)
  {
    $key = $tableName . '.' . $tableAlias;
    
    if (!isset($this->tableSelects[$key])) 
    {
      $this->loadTable($tableName,$tableAlias);
    }
    return $this->tableSelects[$key];
  }
586713
public static function existsTable($tableName)
    {
        if ($tableName === '') {
            throw new \InvalidArgumentException('The table name must not be empty.', 1331315636);
        }

        self::retrieveTableNames();

        return isset(self::$tableNameCache[$tableName]);
    }
690530
public static function fromTable($tableName)
    {
        $repos = Repository::getDefaultRepositoryClassName();

        // Get the create table syntax for the table - we'll analyse this and build our schema accordingly.
        $row = $repos::returnFirstRow(
            "SHOW CREATE TABLE $tableName"
        );

        $sql = $row["Create Table"];

        $lines = explode("\n", $sql);

        // First and last lines aren't needed
        $lines = array_slice($lines, 1, -1);

        $comparisonSchema = new MySqlComparisonSchema();

        foreach ($lines as $line) {
            $line = trim($line);

            // If the line starts with a back tick we have a column
            if ($line[0] == "`") {
                $default = null;

                preg_match("/`([^`]+)`/", rtrim($line, ','), $matches);

                $name = $matches[1];

                $comparisonSchema->columns[$name] = rtrim(trim($line), ",");
            } else {
                $words = explode(" ", $line);

                $indexKeywords = ["PRIMARY", "KEY", "UNIQUE", "FULLTEXT"];

                if (in_array($words[0], $indexKeywords)) {
                    $index = preg_replace('/\s+/', ' ', rtrim(trim($line), ","));
                    $index = preg_replace('/^UNIQUE KEY/', 'UNIQUE', $index);
                    $comparisonSchema->indexes[] = $index;
                }
            }
        }

        return $comparisonSchema;
    }
489293
protected function getTableVariable($table, $tableName)
    {
        $options = $this->getTableOptions($table);
        $result = sprintf("%s\$table = \$this->table(\"%s\", %s);", $this->ind2, $tableName, $options);

        return $result;
    }
798224
protected function _getTableFromString($tableName)
    {

        if ($this->_table instanceof Zend_Db_Table_Abstract) {
            $tableDefinition = $this->_table->getDefinition();

            if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
                return new Zend_Db_Table($tableName, $tableDefinition);
            }
        }

        // assume the tableName is the class name
        if (!class_exists($tableName)) {
            try {
                // require_once 'Zend/Loader.php';
                Zend_Loader::loadClass($tableName);
            } catch (Zend_Exception $e) {
                // require_once 'Zend/Db/Table/Row/Exception.php';
                throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e);
            }
        }

        $options = array();

        if (($table = $this->_getTable())) {
            $options['db'] = $table->getAdapter();
        }

        if (isset($tableDefinition) && $tableDefinition !== null) {
            $options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition;
        }

        return new $tableName($options);
    }
641551
public function fieldExists($fieldName, $tableName)
    {
        $tableFields = $this->getFields($tableName);
        $tableName = strtoupper($tableName);
        if (is_array($tableFields)) {
            $fieldName = strtoupper($fieldName);
            $tableFields = array_map('strtoupper', $tableFields);
            if (in_array("{$tableName}.{$fieldName}", $tableFields)) {
                return true;
            }
        }

        return false;
    }
580878
public function insert($tableName)
    {
        $sql = new Insert($tableName);
        $sql->setAdapter($this->_adapter);
        return $sql;
    }
774481
public function isDbTableExists($tableName)
    {
        $status = false;
        $resultSet = array();

        $query = $this->executeRawQuery("SHOW TABLES LIKE '".trim($tableName)."';");
        if($resultSet)
            $resultSet = $query->toArray();



        if(!empty($resultSet)) {
            $status = true;

        }

        return $status;
    }
27634
public function getTableLimit($tableName)
    {
        if (empty($this->tableLimits[$tableName])) {
            return false;
        }

        $limit = $this->tableLimits[$tableName];
        if (!is_numeric($limit)) {
            return false;
        }

        return $limit;
    }
1370213
public function tableExists( $tablename )
	{
		$sql = "
			SELECT TABLE_NAME
			FROM INFORMATION_SCHEMA.TABLES
			WHERE TABLE_TYPE = 'BASE TABLE'
				AND TABLE_SCHEMA = ?
				AND TABLE_NAME = ?
		";

		$stmt = $this->_conn->create( $sql );
		$stmt->bind( 1, $this->_dbname );
		$stmt->bind( 2, $tablename );
		$result = $stmt->execute();

		if( $result->fetch() !== false ) {
			return true;
		}

		return false;
	}
583497
public function Get($TableName = '') {
		if($TableName)
			$this->Table($TableName);

		$Columns = $this->Database->SQL()->FetchTableSchema($this->_TableName);
		$this->_Columns = $Columns;

		return $this;
	}
1216136
public function getModelJoinByTableName($tableName) {
        foreach ($this->joins as $join) {
            if ($join instanceof ModelJoin && $join->getTableMap()->getName() == $tableName) {
                return $join;
            }
        }

        return null;
    }