Welcome Guest, Not a member yet? Register   Sign In
captcha multiple database question
#1

[eluser]joeizang[/eluser]
Hello folks,

I am sorry to ask this cos I did some searching on the forum and see that similar problems exist but all solutions given have done nothing for me so far so let me give a quick pic of my setup.

I already have a database for my local dev setup and I decided to setup captcha on a form and following the tutorials at okada.no created a database for captcha and then the multi-database setup need arose. I read the userguide and saw the instructions for setting up multiple databases for a single site and followed it and sadly it doesn't work! Here is my code in the config folder in database.php:

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "site";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = false;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

/* Captcha database settings */

$db['dbcaptcha']['hostname'] = "localhost";
$db['dbcaptcha']['username'] = "root";
$db['dbcaptcha']['password'] = "root";
$db['dbcaptcha']['database'] = "ci_captcha";
$db['dbcaptcha']['dbdriver'] = "mysql";
$db['dbcaptcha']['dbprefix'] = "";
$db['dbcaptcha']['pconnect'] = false;
$db['dbcaptcha']['db_debug'] = TRUE;
$db['dbcaptcha']['cache_on'] = FALSE;
$db['dbcaptcha']['cachedir'] = "";
$db['dbcaptcha']['char_set'] = "utf8";
$db['dbcaptcha']['dbcollat'] = "utf8_general_ci";

And so (still following the okada tut on captcha) put the captcha maker and display code in the controller and then realized that I was not even getting to the dbcaptcha! So i did a test controller and model to try it with this code:
Controller:
Code:
class TestCaptcha extends Controller
{
    
    function __contruct()
    {
        $dbl = $this->load->model('testcaptcha','',true);
    }
    
    function index()
    {
        $res = $this->testcaptcha->returnsome();
        
        print_r($res);
    }
}

And the model:

Code:
class TestCaptcha extends Model
{
    private $securedb;
    
    function __contruct()
    {
        
        $securedb = $this->load->database('dbcaptcha',true);
        
    }
    
    function returnsome()
    {
        $q = $this->securedb->get('captcha');
        return $q;
    }
    
}

This still returns an error. This is the example of the error shown from this test.

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: TestCaptcha::$testcaptcha

Filename: controllers/testcaptcha.php

Line Number: 14

Fatal error: Call to a member function returnsome() on a non-object in D:\xampplite\htdocs\mannadev.local\application\controllers\testcaptcha.php on line 14

ALL I ASK IS PLEASE HELP, FROM WHAT I SEE I DON'T HAVE A DATABASE RESOURCE TO WORK WITH. SO WHAT DO I DO?

God bless.
#2

[eluser]danmontgomery[/eluser]
First, you can't have two classes with identical names.

Second, you've misspelled "construct" in both classes, and you never call the parent construct in either.
#3

[eluser]joeizang[/eluser]
Noctrum,

Thanks for taking time to read my post. I just forgot to put that in the test but even in the main application and i still get this error:

Code:
Fatal error: Call to a member function returnsome() on a non-object in D:\xampplite\htdocs\mannadev.local\appfiles\controllers\testcaptcha.php  on line 15

If I understand this right, it means I don't have a database connection resource in the variable I am using to connect to the second active group for the second database. What do I do. Can CI's captcha work with sqlite? I'm not sure howto proceed from here.

Thanks
#4

[eluser]danmontgomery[/eluser]
[quote author="joeizang" date="1279074243"]If I understand this right, it means I don't have a database connection resource in the variable I am using to connect to the second active group for the second database. What do I do. Can CI's captcha work with sqlite? I'm not sure howto proceed from here.[/quote]

You aren't understanding this right...

The error message is that you're calling the method returnsome() on a non-object. As you can see in your controller, you are calling returnsome() on $this->testcaptcha.

The testcaptcha model is never loaded, this is the root of the error message you're seeing now. Even if you do try to load it, it will fail because, as I mentioned, you can't have identically named classes.

Code:
private $securedb;
    
function __contruct()
{
    $securedb = $this->load->database('dbcaptcha',true);
}

Should be

Code:
private $securedb;
    
function __construct()
{
    parent::Model();
    $this->securedb = $this->load->database('dbcaptcha',true);
}

You are also never calling the parent constructor in the controller, as I mentioned.

I'd suggest you open the user guide and do some reading.

http://ellislab.com/codeigniter/user-gui...llers.html
http://ellislab.com/codeigniter/user-gui...odels.html
#5

[eluser]joeizang[/eluser]
I did exactly what you put here... that is where I am getting the above error. I know it seems we green horns seem to be in a hurry but I have been going over this thing for a few hours and I don't understand why it's doing this. But I did apply the corrections you suggested and I am still getting the
Code:
atal error: Call to a member function returnsome() on a non-object in D:\xampplite\htdocs\mannadev.local\appfiles\controllers\testcaptcha.php  on line 15
and like you said before I changed the model name to testcap.php so in the model its

Code:
class Testcap extends Model
{
   private $securedb;

   function __construct()
   {
     parent::Model();
     $this->securedb = $this->load->database('dbcaptcha',true);
   }
}

I am sorry for all the trouble.




Theme © iAndrew 2016 - Forum software by © MyBB