Welcome Guest, Not a member yet? Register   Sign In
Problem with Database Loading
#1

[eluser]axiom82[/eluser]
I have the most hair pulling scenario when trying to load a database on the fly in Code Igniter.

If I use a method to return a string and that string has a number on the end, the number is removed during the database load. If I use a string literal with the same value, the number remains during the database load. Can somebody explain this?

I've done a strcmp() on $db1 and $db2 below and it comes back equal. This issue occurs when sending a database update request using Code Igniter's XMLRPC class.

Does anyone have any idea why $db1 and $db2 are behaving differently?

Here is my code:
Code:
function database_connect(){
    
        $db1 = $this->database('name'); // returns "database_name2" (doesn't work)
        $db2 = "database_name2"; // is "database_name2" (works)
        
        $database = array(
        
            'hostname' => 'localhost',
            'username' => 'user',
            'password' => 'password',
            'database' => $db1, // used here $db2 works, $db1 does not???
            'dbdriver' => 'mysql',
            'dbprefix' => '',
            'pconnect' => TRUE,
            'db_debug' => TRUE,
            'cache_on' => FALSE,
            'cachedir' => '',
            'char_set' => 'utf8',
            'dbcollat' => 'utf8_general_ci'
            
        );
        
        $this->db = $this->load->database($database, true);
    
    }
#2

[eluser]pistolPete[/eluser]
Can you post the full database()-method?
#3

[eluser]axiom82[/eluser]
Yes. Here is the database method which is a shortcut to the usable method in the database model.

Code:
class Copy_Model extends Model {

    function database($field = null){
    
        $this->ci =& get_instance(); // CodeIgniter workaround for model in model
        $this->ci->load->model('database_model');
        $data = $this->ci->database_model->database($field);
        return $data;
        
    }

leads to...

Code:
class Database_Model extends Model {
    
    function database($field = null){
    
        $database = $this->session->userdata('database');
        $query = $this->db->select(array('name', 'accessed', 'modified'))->from('copy_editor.databases')->where('name', $database)->get();
        $data = $query->row_array();
        return (!is_null($field) && isset($data[$field])) ? $data[$field] : $data;
    
    }

//........

I use the database function to return session-based data about the currently selected database I am editing in my application interface. Some of this information pours down into my controller and into my views where it is visible exactly how it should read: "database2".

I did tests on the return string ($db1) vs. the string literal ($db2) and the results with strcmp() and similartext() were identical. There is no difference. Maybe there is some kind of binary data or character set difference between the cookie text version and a simple inline php version of this string? Maybe a utf8 issue? I'm leaning towards it being a Windows Vista/AJAX issue.

Let me know if you have any thoughts. Thank you Smile
#4

[eluser]axiom82[/eluser]
I cleared up the issue. I created my own XMLRPC server to replace the multiple unsolveable issues I encountered while using it. Everything works great now! Even still, how could two identical strings be different??? ($string1===$string2) but not? Hmm, maybe a php or server misconfiguration.




Theme © iAndrew 2016 - Forum software by © MyBB