Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

URGENT connect to SQL server

im trying to connect to SQL server in our office using PHP.

im currently logged onto the network and all of our websites including PHP and IIS is installed on our SERVER01.

our SQL SERVER is installed on SERVER04 but does not have PHP or IIS installed on it.  I can get a connection suing ODBC's DSN configuration, but i dont know how to do this in PHP and query table

i have enabled php_msql.dll on SERVER01 but i get

Fatal error: Call to undefined function mssql_connect() in c:\Inetpub\wwwroot\admin\Personal\index.php on line 10

if i check the php.ini setting SQL is supported so im confused... my SERVER01 is windows 2000....

code:

echo (mssql_connect("Personell","ellanndrd","")) ? "YES": "NO";

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

>i have enabled php_msql.dll on SERVER01 but i get
how?

usually, the php.ini file is the one in the windows folder...
SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ellandrd

ASKER

>>how?

i uncommented it.

my php.ini lives in c:\winnt\php.ini

i have copied msql.dll into winnt folder and system32 too...

>>Have you restarted the server after enabling msql.dll?

im in a office full of engineers all working off the server01 so its isnt really possible until...

php_mssql.dll & php_msql.dll is there a different?  Mmmm hold on i might i selected the wrong one...
am annoyed - i have php_msql.dll uncommented not php_mssql.dll...

let me try my code again and i'll get back to you...
>php_mssql.dll & php_msql.dll is there a different?  Mmmm hold on i might i selected the wrong one...

yes, they are different. please enable php_mssql.dll and try again
OK better progress made - now im getting:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: SERVER04 in c:\Inetpub\wwwroot\admin\Personal\index.php on line 10
NO
my ODBC DSN pointer is called: Personell and it can connect to SQL server OK, but it in PHP that i need to get working,..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok SQL server name is FILE04COMPANYNAME

so my code will be:

mssql_connect("FILE04COMPANYNAME","user","pwd")

??

whats this boolean link thingy at the end?  what goes there?
you can ignore that for the moment (optional parameter)
well it still dont work...
the database im trying to access it highlighted:

www.seandelaney.co.uk/ee.bmp

the name of the server SQL is installed on is \\SERVER04

still not working

code:mssql_connect("FILE04ABZPI,1433","administrator","pwd")
ok guys i still dont have it working! i need more help - i have never played with SQL server before - so i dont know how to work it or connect to it...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: SERVER04 in c:\Inetpub\wwwroot\admin\Personal\index.php on line 10
IP address of server01 (PHP and IIS is installed) is 192.168.0.2
IP address of server04 (SQL server is installed) is 192.168.0.5

my code:

echo (mssql_connect("192.168.0.5","administrator","xxxx")) ? "YES": mssql_get_last_message();

dont work either...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>telnet 192.168.0.5 1433

TELNET dialog appear but nothing is happening... no message appearing...

i will search for client tool...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i get

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 192.168.0.5 in c:\Inetpub\wwwroot\admin\Personal\index.php on line 12
from the client tool i get this:

Server Error in '/webadmin' Application.
--------------------------------------------------------------------------------

Impersonation failure.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Impersonation failure.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[HttpException (0x80004005): Impersonation failure.]
   System.Web.ImpersonationSuspendContext.GetCurrentToken() +197
   System.Web.ImpersonationSuspendContext.Suspend() +53
   System.Web.HttpContext.GetConfig(String name) +104
   System.Web.CustomErrors.GetSettings(HttpContext context, Boolean canThrow) +19
   System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow) +39
   System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) +485
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573



does this mean im connected but there another problem?
is "administrator" a login you created in the SQL Server LOGINS ?
i didnt create it? i assume the username and password was that of the admin account for the whole network? no?
>i assume the username and password was that of the admin account for the whole network? no?

in sql server, you have to explicitely create the logins you want to grant access to for connection.
I am not sure about php (did not try that yet) if it allows windows authentication, but I doubt.

you should create a SQL Logins, grant it permissions in the Personnel database, and use that login+password in the connection
ok i will try that.. but how?

i mean for "you should create a SQL Logins"? how?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK i created new login and set up password and selected personnel database.  grant access was already selected so i left it alone...

i'll try connecting again so i'll brk
I still get unable to connect to server: SERVER04.

here is printscreen of the instance...

http://www.seandelaney.co.uk/mssql.JPG

>SERVER04
the screenshot shows FILE04ABZPI and not SERVER04 ?!

what is this name of SERVER04?
please try to connect using the FILE04ABZPI name instead...
the server mssql is installed on.

i have done so and still get same message
and what is the name FILE04ABZPI shown in the screenshot?
is that not the name of mssql? i have never set up connections before or used mssql.  this is my first time and i was asked to connect to mssql using php as apart of a task...

what is the output of (from dos command line):
PING FILE04ABZPI
PING SERVER04

here is another print screen - maybe this is more help.. as im getting confused

http://www.seandelaney.co.uk/mssql2.JPG
http://www.seandelaney.co.uk/pingfile04abzpi.JPG

pinging server04 nothing happen - could not find host...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>in the service manager window, what is listed in the "server" list?

there is load of items listed...

http://www.seandelaney.co.uk/list.JPG

>>in the enterprise Manager, I see that you have a BKUPEXEC instance on that server, possibly (local) represents the default instance?

i dont know what BKUPEXEC is - i assume my boss set this up to carry out backups....

the database i need to access is called "Personnel" and as you can see it is in default instance (local)(NT Windows).

>>what are the properties of (local) in the enterprise Manager?

when i do this, i get a dialog with lots of tabs - what info are you looking for?
in the enterprise manager, the (local) sql server. when i expand the folder called Security and views subfolders:

Logins
Server Roles
Linked Servers
Remote Servers

under remote servers its name is FILE04ABZPI...

my PHP page exists on a different server than where the MS SQL server is on - you know this right?  (as i said this at the start of the question...)
well, the connection with FILE04ABZPI should then work, can you show me how you defined the login?
what do you mean?

my code
no, in the Enterprise Manager, under LOGINS you did create a login. please show me that form of that login
<?php
$server = "file04abzpi";
$username = "sd";
$password = "???????";

$sqlconnect = mssql_connect($server, $username, $password);

#$sqldb = mssql_select_db("Personnel",$sqlconnect);

#$sqlquery = "SELECT firstName FROM tblPersonnel;";

#$results = mssql_query($sqlquery);

#while ($row = mssql_fetch_array($results))
#{
#      echo $row['firstName']."<br>\n";
#}

#mssql_close($sqlconnect);
?>
any luck?
can you show the database tab on the same form, please
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
osql not recognised... ive tried this on my machine OK?  do i do this on the FILE04ABZPI server?
if i do it on FILE04ABZPI
sorry pages submitted for some reason...?

if i do it on file04abzpi, its like it freezes and does nothing?
does it give you a command prompt like (SQL>)?
possibly post the screenshot.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>assuming that at least the sql client tools are installed

no client tools is installed on the server where PHP is!
the tool was installed on my laptop...
well, then please try the new osql as posted from your laptop
i get "osql" not recognised
You just said it was installed on you laptop
yes and i cant connect to personnel database fine and query it but not using PHP...

the tool used OBDC DSN though... as ive one set up...
the command osql -Sfile04abzpi  -Usd -P<password> dont work - i get osql not recognised...
taken from another question asked:

https://www.experts-exchange.com/questions/20814437/php-connect-sql-server2000-windows-2000-server.html

Extract below:

>>from the manual:

>>The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client >>Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to >>\winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access. Configuration of the client will require >>installation of all the tools.



do i need to copy ntwdblib.dll from FILE04ABZPI to our server where PHP is installed as i done a search on our server (MAIL01ABZPI) where PHP is installed and i cant find that file.  if i search for it on FILE04ABZPI i can find it...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it worked!
i cant believe this - it worked.... excellent! can eat now and pull myself out from this chair...
thank you!
Glad I could help you, took some time to get this working indeed.
yes i know, but we didnt give up...