Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:31:38+00:00 2026-06-12T16:31:38+00:00

i am developing a app that scans/crawls/monitors certain websites the app is available for

  • 0

i am developing a app that scans/crawls/monitors certain websites

the app is available for free at www.linkbook.co

now, i will explain what i want to do:

I have a main DB, that stores the websites, the urls found on the websites and url patterns from each website; The website knows the Db that he has been assigned to, the url knows the website id;

Because i have a 2 GB / DB limit, i need secondary DB’s.

I read all from http://www.yiiframework.com/wiki/123/multiple-database-support-in-yii/ and what Google could find, and there is not a single complete example using dinamicaly the connection;

So, each time my app scans a website, each url found will be inserted in the main DB, and also in the DB that has been assigned to the website that the url belongs to.

In time, the data from the main DB gets deleted, but it is still available in the secondary DB.

So, only the HOT info gets stored in the main but they remain saved in the secondary db’s

The Yii guys give this example, but i need a parameter, from 1 to N, N=1->infinite,in order to switch to the right DB.

class MyActiveRecord extends CActiveRecord {
    ...
    private static $dbadvert = null;

    protected static function getAdvertDbConnection()
    {
        if (self::$dbadvert !== null)
            return self::$dbadvert;
        else
        {
            self::$dbadvert = Yii::app()->dbadvert;
            if (self::$dbadvert instanceof CDbConnection)
            {
                self::$dbadvert->setActive(true);
                return self::$dbadvert;
            }
            else
                throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));
        }
    }
    ...

$dbadvert needs to be dinamic, this is my problem.

also, the tables from the secondary DB’s are not exactly the same, as i dont need all the fields from all the tables, and some tables get dropped also, so i need a model;

the model i can write it, it’s not hard, i will just delete some fields;

this is what i have now, just the insert, in a specific DB, db1 a.k.a. linkbookco1

$command = Yii::app()->db1->createCommand("INSERT INTO `url` (
`id` ,
`website_id` ,
`link` ,
`name` ,
`created` ,
`instance_scanner_id` ,
`status`
)
VALUES (
NULL ,  '".($model_url->website_id)."',  '".($model_url->link)."',  '".($model_url->name)."',  '".($model_url->created)."',  '".($model_url->instance_scanner_id)."',  '".($model_url->status)."'
);
");
$command->query();

db1 and it’s params are mentioned in the config file, as the yii developers say;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:31:40+00:00Added an answer on June 12, 2026 at 4:31 pm

    from your example I can guess you have a secondary database connection configured in your app like

    'dbadvert' => array(
        'class' => 'CDbConnection',
        ...
    )
    

    the point where you need to get the database connection you have this:

    self::$dbadvert = Yii::app()->dbadvert;
    

    So, to have multiple database connections you’d need to add them to your database configuration

    'dbadvert1' => array(
        'class' => 'CDbConnection',
        ...
    )
    'dbadvert2' => array(
        'class' => 'CDbConnection',
        ...
    )
    

    And in your code you can do something like

    self::$dbadvert = Yii::app()->getComponent("dbadvert".Yii::app()->request->getQuery('dbid', ''));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an app that periodically fetches data from server. Now I'm using a
I'm developing an app that will make extensive HTTP requests. I know for a
I am developing an app that will request the profile picture URL of some
I'm developing an app that calculates poker odds, and now I'm facing some problems
I am currently developing an app that will contain large amounts of audio, around
I'm developing a small utility app that scans 2D barcodes, and then submits each
When developing an app that will listen on a TCP/IP port, how should one
I am developing an app that will take a photo and upload it to
I am developing an app that will allow users to capture images of secure
I'm interested in developing an app for iPhone that can scan and read ITF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.