Welcome Guest, Not a member yet? Register   Sign In
Having problem to connect SQL Server
#1

[eluser]Sandy_s[/eluser]
Hi, I'm new to CodeIgniter. I got problem to connect the SQL Server. Is there any guides or samples for this. TIA
#2

[eluser]xwero[/eluser]
which version of CI are you using? If you are using 1.6.x and a mysql version under 4.1 you have to hack the mysql driver. In the database config file i set $db['default']['char_set'] and $db['default']['dbcollat'] to an empty string and the hack is
Code:
function db_set_charset($charset, $collation)
    {
        if($charset == '' && $collation == ''){ return TRUE; } // added
        return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
    }
If you meet the requirements can you show the database setting you use (without real username and password of course) and how you connect to the database.
#3

[eluser]Sandy_s[/eluser]
Thanks for the reply. But I was meant to the MSSQL, rather than mysql.

My Database.php configurations as follows:

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

$db['default']['hostname'] = "FD109";
$db['default']['username'] = "sa";
$db['default']['password'] = "123456";
$db['default']['database'] = "mydb";
$db['default']['dbdriver'] = "mssql";
$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";

?>


And controller configurations as follows:

<?php
class Application extends Controller {

function Application()
{
parent::Controller();
}

function index()
{
$data['query'] = $this->db->get('dbo.owner');
$this->load->view('welcome_message',$data);
}

}
?>

Returned error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Application: $db

Filename: controllers/application.php

Line Number: 11


Any suggestion?
#4

[eluser]xwero[/eluser]
do you autoload the library?
If you do the alternative is to add
Code:
$this->load->database();
to your controller construct method (Application in your case)
#5

[eluser]senojeel[/eluser]
Have you tried just loading Scaffolding? What version of SQL server are you connecting to?
#6

[eluser]Sandy_s[/eluser]
Thank you all very much!
[quote author="xwero" date="1204643658"]do you autoload the library?
If you do the alternative is to add
Code:
$this->load->database();
to your controller construct method (Application in your case)[/quote]
Have tried this, but still failed.

[quote author="senojeel" date="1204680594"]Have you tried just loading Scaffolding? What version of SQL server are you connecting to?[/quote]
Yes, tried just loading Scaffolding. Seems to be able to connect, could see the field, but failed to insert records.
The version of SQL server is 2005.
#7

[eluser]xwero[/eluser]
Does it support char_set and dbcollat? (i just checked the driver and it's not used)

Try to set the pconnect to FALSE.
#8

[eluser]stanleyxu[/eluser]
I think this issue should be reported to bug tracker.
#9

[eluser]senojeel[/eluser]
Just FYI, I was connecting to a SQL 2000 server no problem. I tried to connect to 2005 server and it won't connect. I am still troubleshooting. I can connect to my 2005 server with other php scripts.
#10

[eluser]porksmash[/eluser]
I was able to connect to SQL server 2005. First, you have to make sure that SQL Server has Mixed Mode authentication enabled, and a password set for the sa user. Next is to make sure that SQL Server allows connections via TCP/IP. I don't know if it matters, but I set SQL Server to not use dynamic ports, only port 1433. You can do this in the SQL Server Configuration Manager that is installed along with the server.

Your database.php config file should look like this:
Code:
$db['default']['hostname'] = "<hostname>\<instance>";
$db['default']['username'] = "sa";
$db['default']['password'] = "<password>";
$db['default']['database'] = "<database>";
$db['default']['dbdriver'] = "mssql";
$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";

I had SQL Server installed on the same PC Apache was running on, but I was unable to connect with the hostname set to either 127.0.0.1\SQLEXPRESS or localhost\SQLEXPRESS, while I would assume both should work. Only using the actual computer name (from the Computer Name tab of System Properties) would connect properly. Hope this helps somebody. Sure is a lot of trouble to get connected, and even then SQL Server is not fully supported (just try using scaffolding!).




Theme © iAndrew 2016 - Forum software by © MyBB