Table of Contents
Yii ExtendedActiveRecord enhanced version of ActiveRecord adds multi-database connection binding function, activerecord
Ralis connects to the remote database and prompts ActiveRecord::ConnectionNotEstablished. Local pl/sql can access the remote database
How to connect yii20 to XAMPP database?
Home Backend Development PHP Tutorial Yii ExtendedActiveRecord enhanced version of ActiveRecord adds multi-database connection binding function, activerecord_PHP tutorial

Yii ExtendedActiveRecord enhanced version of ActiveRecord adds multi-database connection binding function, activerecord_PHP tutorial

Jul 13, 2016 am 10:21 AM
activerecord yii Function increase Enhance database Version binding connect

Yii ExtendedActiveRecord enhanced version of ActiveRecord adds multi-database connection binding function, activerecord

ExtendedActiveRecord inherits from CActiveRecord, so the basic functions are the same as CActiveRecord

To add support for multiple database connections, a callback to the connectionName() method is added. The usage is consistent with the existing tableName() method and returns the string of the name of the database connection component.

If this method is not defined, the default database connection (db) is used

The source code is as follows:

class ExtendedActiveRecord extends CActiveRecord
{
    public static $db = array();

    /**
     * @return CDbConnection
     * @throws CDbException
     */
    public function getDbConnection()
    {
        $componentName = $this->connectionName();
        if (isset(self::$db[$componentName])) {
            return self::$db[$componentName];
        } else {
            self::$db[$componentName] = Yii::app()->getComponent($componentName);
            if (self::$db[$componentName] instanceof CDbConnection)
                return self::$db[$componentName];
            else {
                $message = 'Active Record keyword requires a "' . $componentName . '" CDbConnection application component.';
                Yii::log($message, CLogger::LEVEL_ERROR, 'extended');
                throw new CDbException(Yii::t('yii', $message));
            }
        }
    }

    public function connectionName()
    {
        return 'db';
    }
}
Copy after login

Example:

class SomeModelClass extends ExtendedActiveRecord
{
    ......

    public function connectionName() {
        return 'some-db-connection';
    }

    ......
}
Copy after login

 

Ralis connects to the remote database and prompts ActiveRecord::ConnectionNotEstablished. Local pl/sql can access the remote database

You can connect remotely within the LAN, but cannot connect to the WAN using an external IP address?
The IP address and database port need to be mapped on the router

How to connect yii20 to XAMPP database?

yii2.0 officially provides two templates
Let’s talk about the basic version first:
Just modify config/db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2',
'username' => 'root',
'password' => ; '',
'charset' => 'utf8',
'tablePrefix' => 'hpcms_',
];

where dbname refers to the database name and host is The host and tablePrefix are the table prefix

which is similar to the advanced version. Modifying the common/config/main-local.php
configuration parameters is basically the same as above!

In this way, you can connect to the database (of course you have to start mysql. If it is another database, please search it. Basically, you can configure the parameters)

For how to operate the database (Add, delete, modify and check) Please see the documentation ActiveRecord and Model (after designing the table structure, you can use Gii to quickly generate the Model)

If you want to know more, it is most practical to read the documentation

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/860062.htmlTechArticleYii ExtendedActiveRecord enhanced version of ActiveRecord adds multi-database connection binding function, activerecord ExtendedActiveRecord inherits from CActiveRecord, so the basic functions are the same as CActiveReco ...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to bind the Xiaomi car app to the charging pile device How to bind the Xiaomi car app to the charging pile device Apr 01, 2024 pm 06:52 PM

The latest Mi su7 model car launched by Xiaomi has dominated various hot search lists. Many users who happen to want to buy a car have chosen Xiaomi su7 model car for purchase. So how do you use your Xiaomi car app to bind the car after picking up the car? If you decide to use a home charging pile for charging, this tutorial guide will give you a detailed introduction, I hope it can help you. First, we open the Xiaomi mobile app, click the My button in the lower right corner, and then in the My interface, you can see the option of home charging pile. After entering the page to bind the charging pile, click the scan code button below and scan the QR code on the charging pile. The QR code can be used to bind the charging pile to the app.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

What is GateToken(GT) currency? Introduction to GT coin functions and token economics What is GateToken(GT) currency? Introduction to GT coin functions and token economics Jul 15, 2024 pm 04:36 PM

What is GateToken(GT) currency? GT (GateToken) is the native asset on the GateChain chain and the official platform currency of Gate.io. The value of GT coins is closely related to the development of Gate.io and GateChain ecology. What is GateChain? GateChain was born in 2018 and is a new generation of high-performance public chain launched by Gate.io. GateChain focuses on protecting the security of users' on-chain assets and providing convenient decentralized transaction services. GateChain's goal is to build an enterprise-level secure and efficient decentralized digital asset storage, distribution and transaction ecosystem. Gatechain has original

See all articles