SQL server error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mdbull73
Forum Newbie
Posts: 3
Joined: Mon Jun 08, 2009 12:58 pm

SQL server error

Post by mdbull73 »

Hello all,

I'm a first time poster and a complete WAMP noob.

Anyways, I'm trying to set up a intranet using APache and SqlSErver express 2005.

Apache is set up, but I'm having trouble accessing the database.

Here's the error I got when I typed dbinfo.php into my address window:

Fatal error: Call to undefined function mssql_connect() in C:\WebServer\Apache2\htdocs\phpinfo.php on line 8

Here's my code:

Code: Select all

 
<?php
$myServer = "SQLEXPRESS\\ComputerName";
$myUser = "sa";
$myPass = "password";
$myDB = "MyDb.mdf"; 
 
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 
 
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB"); 
 
//declare the SQL statement that will query the database
$query = "SELECT * ";
$query .= "FROM Employees ";
 
//execute the SQL query and return records
$result = mssql_query($query);
 
$numRows = mssql_num_rows($result); 
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 
 
//display the results 
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//close the connection
mssql_close($dbhandle);
?> 
 
 
I installed the sql libaries php_sqlsrv_ts.dll and php_sqlsrv.dll in the C:\WebServers\PHP\ext folder and rebooted the computer.

When I run a simple php script, it works, so I know Apache is picking up PHP. But how can I make the PHP script recognize 'mssql_connect' and other functions?

Thanks again to all for any help.

Mike
Last edited by Benjamin on Mon Jun 08, 2009 1:12 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: SQL server error

Post by mikemike »

Have you loaded the extensions in your php.ini?

I know the mssql extension requires extension=php_mssql.dll being loaded.
mdbull73
Forum Newbie
Posts: 3
Joined: Mon Jun 08, 2009 12:58 pm

Re: SQL server error

Post by mdbull73 »

Thanks for the answer Mike.

It looks like that extension was commented out.

I uncommented the line. But do I have to restart Apache to make it work?
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: SQL server error

Post by mikemike »

Probably, yeah
mdbull73
Forum Newbie
Posts: 3
Joined: Mon Jun 08, 2009 12:58 pm

Re: SQL server error

Post by mdbull73 »

I have these lines uncommented in my php.ini file:

extension=php_msql.dll
extension=php_mssql.dll
extension=php_sqlsrv_ts.dll
extension=php_mysql.dll
Post Reply