Page 1 of 1

Fatal error: Call to undefined function mssql_connect()

Posted: Sun Aug 21, 2005 2:59 am
by raymondkwoods
Hello,

New to PHP and to the forum. I am developing a commercial website in PHP 5 and have set up a small test network. I have one server running Windows NT 4.0 and ISS 4.0 and another with Microsoft SQL Server 2000 Personal Edition installed. I am doing all my development on a Compaq presario desktop. I successfully installed PHP and everything was going fine until I tried accessing the database. I am getting the following error:

Code: Select all

Fatal error: Call to undefined function mssql_connect() in C:\InetPub\wwwroot\Test\test.php on line 7
Here is the script:

Code: Select all

<?php
$server="DEVSERV,1433";
$username="Administrator";
$password="password";

$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db("testdb",$sqlconnect);
$sqlquery="SELECT * FROM test;";
$results= mssql_query($sqlquery);

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

mssql_close($sqlconnect);
?>
I have done the following:
1. Installed the SQL Client Tools on the web server
2. Uncommented the line extension=php_mssql.dll in the php.ini file
3. Copied the php_mssql.dll file to the WINNT\System32 directory and the php\ext directory.

I tried running the following script that I found on another forum:

Code: Select all

$ext = get_loaded_extensions();
if(in_array('mssql', $ext))
echo 'you have mssql installed';
else
echo 'you do NOT have mssql installed';
and it printed you do NOT have mssql installed. How do I install it? PHP manual was no help and I couldn't find anything else on this forum that I could use. Only other thing I can think of that I haven't tried yet is recompiling using --with-mssql. But I have no idea how to do that or if it is even neccesary.

Any help would be greatly appreciated.


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Aug 21, 2005 4:51 am
by feyd
windows builds don't need recompile to install functionality.

Did you remember to restart the web server (at least) after making these changes?

System DSN and odbc_connect doesn't work either

Posted: Sun Aug 21, 2005 9:10 pm
by raymondkwoods
I did reboot both servers and still got the same error. I also tried setting up a system DSN on the server that MS SQL Server is installed on and tried the following code:

Code: Select all

$dsn="testDSN";
$username="Administrator";
$password="password";

$sqlconnect=odbc_connect($dsn,$username,$password);
$sqlquery="SELECT * FROM test;";
$process=odbc_exec($sqlconnect, $sqlquery);

while(odbc_fetch_row($process)){
  $companyName = odbc_result($process,"test_ID");
  echo "$companyName<br>"; 
}

odbc_close($sqlconnect);
I got the following error:

Code: Select all

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\InetPub\wwwroot\test\test.php on line 23

Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in C:\InetPub\wwwroot\test\test.php on line 25

Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in C:\InetPub\wwwroot\test\test.php on line 27

Warning: odbc_close(): supplied argument is not a valid ODBC-Link resource in C:\InetPub\wwwroot\test\test.php on line 32
I guess it's possible that I am not setting up the DSN correctly. My first php project doesn't seem to be going to well. :(

Posted: Sun Aug 21, 2005 9:12 pm
by feyd
do a phpinfo() script. Make sure the php.ini is being loaded from where you think it is, and that the settings and extensions loaded match what you think they should be.

Solved problem

Posted: Wed Aug 24, 2005 11:12 pm
by raymondkwoods
Okay I figured out what i was doing wrong. Either one of the following now works:

Code: Select all

include "adodb\adodb.inc.php";

$db =& ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=DEVSERV;Database=test;";
$db->Connect($dsn,'test','test'); 

$sql = "SELECT test FROM testDB";

$rs = $db->Execute($sql);

while (!$rs->EOF) 
{
   var_dump($rs->fields);
   $rs->MoveNext();
}
or

Code: Select all

$dsn="Driver={SQL Server};Server=DEVSERV;Database=test;";
$username="test";
$password="test";

$sqlconnect=odbc_connect($dsn,$username,$password);
$sqlquery="SELECT * FROM testDB;";
$process=odbc_exec($sqlconnect, $sqlquery);

while(odbc_fetch_row($process))
{
  $test1= odbc_result($process,"test");
  echo "$test1,"; 

  $test2= odbc_result($process,"test2");
  echo "$test2,";

  $test3= odbc_result($process,"test3");
  echo "$test3";

  echo "<br>";
}

odbc_close($sqlconnect);
Had to change authentication from windows only to SQL Server and Windows under the security tab of the SQL Server properties.

Thanks