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

  • Home
  • SEARCH
  • 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 8762359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:30:42+00:00 2026-06-13T15:30:42+00:00

My app has one primary database, and many secondary databases. I have a limitation

  • 0

My app has one primary database, and many secondary databases. I have a limitation of 2 GB per database, so I must have multiple databases.

The data must be saved in the main database and in one of the many secondary databases. From the primary database, I know which secondary database to save the data.

My databases are not identical, there are small differences. I created a model for the main database and another model for the secondary databases.

This is the error:

CException

SlaveUrl and its behaviors do not have a method or closure named "findByUrl".

This is the line that i am fighting agains:

$record = SlaveUrl::model()->findByUrl($query);

and it’s found in this code:

<?php


class ScannerCommand extends CConsoleCommand {

    private $time;
    private $urls = 0;

    /**
     * Executes the command.
     * @param array command line parameters for this command.
     */
    public function run($args) {
        // $args gives an array of the command-line arguments for this command
        $this->time = time();
        $instance_scanner = new InstanceScanner();
        $instance_scanner->create = $this->time;
        $instance_scanner->urls = 0;
        if ($instance_scanner->save()) {
            echo 'scanner start' . PHP_EOL;
            $criteria = new CDbCriteria();
            $criteria->condition = 'status=:status';
            $criteria->order = '`update` asc';
            $criteria->limit = 1;
            $criteria->params = array(':status' => 1);
            $model_website = Website::model()->find($criteria);
            $model_website->update = $this->time;
            $model_website->save();
            echo 'scanning ' . $model_website->name . ' ... ' . PHP_EOL;
            $model_pattern_url = PatternUrl::model()->findByAttributes(array('website_id' => $model_website->id));
            //$website_file_content = file_get_contents($model_website->link);
            $website_file_content = CurlTool::fetchContent($model_website->link,array(),true);
            preg_match_all('/<a href=[\'"](.*?)[\'"].*?>([^<]+)<\/a>/ims', $website_file_content, $matches_url);
            if ((is_array($matches_url[0])) && (count($matches_url[0]) > 0))
                foreach ($matches_url[0] as $key => $value) {
                    $ok = false;
                    preg_match_all($model_pattern_url->pattern, $matches_url[1][$key], $matches_pattern_url);
                    //print_r($matches_pattern_url);
                    if ((is_array($matches_pattern_url)) && (count($matches_pattern_url[0]) > 0))
                        if (strpos($matches_url[1][$key], $matches_pattern_url[0][0]) !== false)
                            $ok = true;

                    SlaveUrl::$server_id = $model_website->server_id;

                    echo $query = "select * from `url` where  ( ( `website_id`='".($model_website->id)."' ) and ( `link`='".($matches_url[1][$key])."' ) ) or (  ( `website_id`='".($model_website->id)."' ) and ( `name` = '".(addslashes($matches_url[2][$key]))."' ) );";

                    $record = SlaveUrl::model()->findByUrl($query);

                    if( $record == null )
                    {

                    $model_slave_url = new SlaveUrl();
                    $model_slave_url->website_id = $model_website->server_id;
                    $model_slave_url->link = $matches_url[1][$key];
                    $model_slave_url->name = $matches_url[2][$key];
                    $model_slave_url->created = time();
                    $model_slave_url->status = 1;

                    if( $model_slave_url->save() )
                    {

                    //$data = Url::model()->findByAttributes(array('website_id' => $model_website->id, 'link' => $matches_url[1][$key], 'name' => $matches_url[2][$key]));
                    $query = "select * from `url` where  ( ( `website_id`='".($model_website->id)."' ) and ( `link`='".($matches_url[1][$key])."' ) ) or (  ( `website_id`='".($model_website->id)."' ) and ( `name` = '".(addslashes($matches_url[2][$key]))."' ) );";
                    echo $query.'<br>';
                    //$command_slave = ;
                    $command = Yii::app()->db->createCommand($query);
                    $data = $command->queryAll();
                    if((count($data)==0) && ($ok === true)) {
                        $model_url = new Url();
                        $model_url->website_id = $model_website->id;
                        $model_url->link = $matches_url[1][$key];
                        $model_url->name = $matches_url[2][$key];
                        $model_url->created = $this->time;
                        $model_url->instance_scanner_id = $instance_scanner->id;
                        $model_url->status = 0;
                        if ($model_url->save())
                            $this->urls++;
                        $command = "INSERT INTO `url` (`id` ,`website_id` ,`link` ,`name` ,`created` ,`instance_scanner_id` ,`status`)VALUES (NULL ,  '".($model_url->website_id)."',  '".($model_url->link)."',  '".(addslashes($model_url->name))."',  '".($model_url->created)."',  '".($model_url->instance_scanner_id)."',  '".($model_url->status)."');";
                    }

                    }

                    }

                }
            echo $this->urls . ' new urls found' . PHP_EOL;
            $instance_scanner->urls = $this->urls;
            $instance_scanner->save();
            echo 'scanner stop';
        }
        else echo 'something went wrong while trying to start the scanning process';
    }

    /**
     * Provides the command description.
     * This method may be overridden to return the actual command description.
     * @return string the command description. Defaults to 'Usage: php entry-script.php command-name'.
     */
    public function getHelp() {
        return 'Usage: how to use this command';
    }

}

this is the main model:

<?php

/**
 * This is the model class for table "url".
 *
 * The followings are the available columns in table 'url':
 * @property string $id
 * @property integer $server_id
 * @property integer $website_id
 * @property integer $slave_url_id
 * @property string $link
 * @property string $name
 * @property integer $created
 * @property integer $instance_scanner_id
 * @property integer $status
 */
class Url extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Url the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'url';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('server_id, website_id, slave_url_id, link, name, created, instance_scanner_id, status', 'required'),
            array('server_id, website_id, slave_url_id, created, instance_scanner_id, status', 'numerical', 'integerOnly'=>true),
            array('link, name', 'length', 'max'=>255),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, server_id, website_id, slave_url_id, link, name, created, instance_scanner_id, status', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'server_id' => 'Server',
            'website_id' => 'Website',
            'slave_url_id' => 'Slave Url',
            'link' => 'Link',
            'name' => 'Name',
            'created' => 'Created',
            'instance_scanner_id' => 'Instance Scanner',
            'status' => 'Status',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('server_id',$this->server_id);
        $criteria->compare('website_id',$this->website_id);
        $criteria->compare('slave_url_id',$this->slave_url_id);
        $criteria->compare('link',$this->link,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('created',$this->created);
        $criteria->compare('instance_scanner_id',$this->instance_scanner_id);
        $criteria->compare('status',$this->status);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}

and this is the Slave model:

<?php

/**
 * This is the model class for table "url".
 *
 * The followings are the available columns in table 'url':
 * @property string $id
 * @property integer $website_id
 * @property string $link
 * @property string $name
 * @property integer $created
 * @property integer $status
 */
class SlaveUrl extends HActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Url the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'url';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('website_id, link, name, created, status', 'required'),
            array('website_id, created, status', 'numerical', 'integerOnly'=>true),
            array('link, name', 'length', 'max'=>255),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, website_id, link, name, created, status', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        'relation_website'=>array(self::BELONGS_TO,'Website','website_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'website_id' => 'Website',
            'link' => 'Link',
            'name' => 'Name',
            'created' => 'Created',
            'status' => 'Status',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('website_id',$this->website_id);
        $criteria->compare('link',$this->link,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('created',$this->created);
        $criteria->compare('status',$this->status);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}

along with the special class that assigns the right slave DB Connection:

<?php

class HActiveRecord extends CActiveRecord

{

public static $server_id=1;
   public static $master_db;

   public function getDbConnection()

   {



         self::$master_db=Yii::app()->{"db".self::$server_id};      

         if(self::$master_db instanceof CDbConnection)

         {

            self::$master_db->setActive(true);

            return self::$master_db;

         }

         else

            throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));



   }

   public function getDbConnection2()

   {

      if(self::$master_db!==null)

         return self::$master_db;

      else

      {

         self::$master_db=Yii::app()->db1;

                 echo self::$master_db->connectionString;



         if(self::$master_db instanceof CDbConnection)

         {

            self::$master_db->setActive(true);

            return self::$master_db;

         }

         else

            throw new CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));

      }

   }

}

?>
  • 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-13T15:30:44+00:00Added an answer on June 13, 2026 at 3:30 pm

    There’s no method called findByUrl() in the class SlaveUrl or HActiveRecord or CActiveRecord
    Which is what is causing the error.

    There is findBySql though. http://www.yiiframework.com/doc/api/1.1/CActiveRecord#findBySql-detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam making an app which has one index.php file. I also have these other
I am working on an android app that has a database in which one
I'm maintaining a Windows app that has multiple forms in the one window (
I have 2 models in my rails app, one with an UUID primary key
I have an app with a primary view that has a UITabBarController with 5
Im currently doing a console app that has to send scheduled emails. In one
I've got some XML resources in my Android app. Each one has a different
I'm building an app that currently has 3 ViewControllers. One of them is used
Okay, when my app starts it has two tabs, and one action in the
I created a SQLite database that currently has only one table. I connected it

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.