Click to See Complete Forum and Search --> : How can I create a MS SQLServer connection


Anon
08-02-2000, 07:07 AM
How can I create MS SQLServer connection,and how can I open a SQLServer database in PHP4?
in ASP,I can use:
set objDB = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.RecordSet")
objDB.Open "DateBase", "user", ""
set objRS = objDB.Execute( SQLStr )
but how can I do it in php4?

I tried mssql_connect(SQLServer),but IIS tell me he can't find function mssql_connect().

Anon
08-02-2000, 09:03 AM
You may need ntwdblib.dll

Anon
08-02-2000, 03:21 PM
You must first create an ODBC dsn in control panel.

This code will work:

$conn = odbc_connect("DataSourceName", "Username", "Password");

Then query the database:

$q = "select field from table";
$results = odbc_do($conn, $q);

while(odbc_fetch_into($results, &$row)) {
$field = $row[0];
//do something with data
}

Anon
08-03-2000, 04:34 AM
You could always talk to it as a Sybase DB, since MSSQL (up to 6.5 anyways, and 7.0 is compatible) is really a Sybase DBMS covered in Microsoft gooey dressing.

Make sure you are using the Sybase libraries, or there will be trouble. This works fine from Linux with sybase-ct compiled in and Sybase-ASE drivers in /home/sybase. I assume the Sybase DLL under NT will perform as well or better than ODBC as the sybase-ct code under Linux beats ODBC in speed from what I can tell.

$dbms = "dns.server.name";
$user = "username";
$pass = "password";

$cs = sybase_connect($dbms, $user, $pass);
sybase_query("USE databasename", $cs);

or

sybase_select_db("databasename", $cs);

$rs = sybase_query("SQL", $cs);

$result_array = sybase_fetch_array($cs);

sybase_free_result($rs);
sybase_close($cs);

Give that a try, that's what we use on our website against an MSSQL 6.5 NT box. Tis quick too. (not as fast as MySQL, but I love my triggers and stored procedures, NT hohum)

Chris