Author |
Topic |
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-12 : 19:37:28
|
Good day!I change my database from mysql to mssql, so I need to change the connection code in my php. I’m not familiar about the codes using mssql. Now cannot connect to my database.I used the following:php 5.1.4 IIS 6.0Microsoft SQL Server 2005 Express EditionSQL Server Management Studio Express Here is my code:[php]<?php//session_start(); //session_regenerate_id(); //if($_SESSION['loggedin']){ //the user is already logged in, lets redirect them to the other page // header("Location:company.php"); //} $server = "ISM\SQLEXPRESS";//$db = "dbtest";$connectOptions = array("Database" => "dbtest");//Because UID and PWD are not specified in the connection option, the connection is made with Windows Authentication.$conn = mssql_connect($server) or die("Could not connect");$selected = mssql_select_db($connectOptions)or die("Cannot select DB"); $department = $_POST['department']; $username = $_POST['username']; $sql=mssql_query("SELECT `Department`, `Username` FROM `tbluser` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mssql_min_error_severity()); $ct = mssql_num_rows($sql); if($ct == 1) { // im guessing this means that the user is valid. $_SESSION['loggedin'] = true; // now that the user is valid we change the session value. $row = mssql_fetch_assoc($sql); //$_SESSION['username'] = $row['Username'] ; //$_SESSION['department'] = $row['Department']; $Departments=array('aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj'); if (in_array($row['Department'], $Departments)){ header ('Location:company.php'); }else{ echo "Incorrect Username or Department"; header ('Location:index.php'); } }?>[/php]And when I run this code the result is:Cannot select DBThank you in advance |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-12 : 20:06:59
|
have the "or die" show the real error message, or take it out altogether so u can see it. then post the actual error.did you ever register ntwlib.dll? |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-13 : 01:10:27
|
quote: Originally posted by russell have the "or die" show the real error message, or take it out altogether so u can see it. then post the actual error.did you ever register ntwlib.dll?
I change my code to see the real errorHere is my new code:$db = "dbtest"; $selected = mssql_select_db($db) or die('MSSQL error' . mssql_get_last_message()); and the output is:MSSQL error.The several principal "[domain name]\IUSR_[computer name]" is not able to access the databse "database name" under the current security context.Honestly, I have no idea regaeding this error.I changed the version of my ntwdblib.dll into 2000.80.194.0 and it is on the C:\php and C:\WINDOWS\system32 |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-13 : 05:41:43
|
I try a new code:[PHP]$db = "dbtest"; $selected = mssql_select_db($db) or die('MSSQL error' . mssql_get_last_message()); [/PHP]and the output is:MSSQL error.The several principal "[domain name]\IUSR_[computer name]" is not able to access the databse "database name" under the current security context.Then I research about this error and I find a step to fix the error, but I can't follow the steps because I can't find what they say in the steps.here is the step:To fix this SQL Server Management Studio 2008 (maybe in 2005 too), please do the following: 1.Open SQL Server Management Studio 2008 2.Connect to the database server as normal 3.Press F7 to open the "Object Explorer Details" window or click "View" >> "Object Explorer Details" 4.In the object explorer details window expand by double click on "Databases" 5.Right click on the column header and deselect "Collation" from the menu that will pop up 6.From the object explorer, refresh the "Databases" I don't know what the appearance is if I am already in the Object Explorer Details view. And I can’t see the column header and also the Collation. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-13 : 20:47:41
|
I'm using Windows Authentication, and I change my authentication mode into mixed. But when I try to login using SQL Server Auhtentication using sa as a username and xoxoxo as password. I got an error saying: Unabled to connect user:reason disabled. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-13 : 22:08:49
|
need to enable sql authentication (mixed mode) on sql server |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-14 : 00:49:55
|
I am already in the mixed mode.But I need to only used the windows authentication. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-14 : 12:19:09
|
are u running iis or apache? give the web server service account permission on sql |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-14 : 20:02:40
|
I used IIS. What do you mean permission from webserver?Thank you |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-14 : 21:58:29
|
The service account for IIS needs a login and permissions on the SQL Server.Unless you're trying to pass the users credentials.Have a look at this: http://technet.microsoft.com/en-us/library/dd296638(WS.10).aspx |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-15 : 02:06:47
|
What do you mean IIS needs a login and Permission? I don't know how can do it... |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-15 : 02:18:40
|
NOw, I try the steps that the link you given..I will update you if it is work...Thank you |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-15 : 02:20:38
|
you want to use NT Authentication. Who's credentials do you want to pass?I fully suspect you haven't read the links I've provided or googled any of the terms unfamiliar to you -- which you need to do. |
|
|
newphpcoder
Starting Member
23 Posts |
Posted - 2010-10-17 : 19:53:33
|
I read the link that you gave,but i can't follow the steps because in a server that I'm using theres no computer enrolled.Because it is for a testing. |
|
|
|