Welcome Guest, Not a member yet? Register   Sign In
Need some help with sqlsrv
#1

[eluser]tcampion[/eluser]
I'm seeing performance issue and suspect I just have something misconfigured.

When I connect to my db using the following php script it responds within 2 seconds with all the data(3000+ worth of results).

Code:
<?php

$serverName = "vsql030.somewhere.com, 2433";

/* Get UID and PWD from application-specific files.  */
$uid = "my_username";
$pwd = "my_password";
$connectionInfo = array( "UID"=>$uid,
                         "PWD"=>$pwd,
                         "Database"=>"MY_DB");

/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Unable to connect.</br>";
     die( print_r( sqlsrv_errors(), true));
}

$tsql = "SELECT * FROM Customer";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
     echo "Error in executing query.</br>";
     die( print_r( sqlsrv_errors(), true));
}

/* Retrieve each row as an associative array and display the results.*/
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
      echo $row['ID'].", ".$row['Name']."\r\n";
}


/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?&gt;


When I run the following it takes approximately 3 minutes to return the same results.

My code igniter DB information looks like this

Code:
app/config/database
*****************************************************
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'vsql030.somewhere.com, 2433';
$db['default']['username'] = 'my_username';
$db['default']['password'] = 'my_password';
$db['default']['database'] = 'MY_DB';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Im testing with the following in codeigniter

app/models/customer.php
*****************************************************

&lt;?php

class Customer extends CI_Model{
    
    function getAll(){
      
        $query = $this->db->query('SELECT * FROM Customer');
        //$query = $this->db->query('SELECT * FROM Customer WHERE ID < 7800');
        echo $query->num_rows();
        
        foreach ($query->result() as $row)
        {
            echo $row->ID;
            echo $row->Name;
            echo $row->noc;
        }
    }
    
    
}

I've swapped out the sqlsrv driver based on a few threads I read but none of that seems to improve performance any at all. The DB Im connecting to is sql server 2005, and im running codeigniter from wamp on my local win xp machine. I've installed sqlncli.msi, and microsoft drivers for php SQLSRV20.EXE in my php/ext dir extension=php_sqlsrv_53_ts_vc9.dll is in the php.ini.

Happy to try any suggestion

Please tell me Im just overlooking something simple.
#2

[eluser]smilie[/eluser]
Not sure what the problem could be, but you could use these two:

http://ellislab.com/codeigniter/user-gui...hmark.html

and

http://ellislab.com/codeigniter/user-gui...iling.html

To try to trace the origin of a problem.

Also, I really do not approach where you scoop data in the model itself.
I preffer:

Code:
class Customer extends CI_Model{
    
    function getAll()
    {
        return $this->db->select('*')->from('customer')->get()->result_array; // this will return array, void _array and you will get object back;
    }
}

This will return it all. Then in your controller, or even in the view you can do:
echo $result['dbValue'] and so on...

Cheers,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB