# Apache,PHP + MSSQL support?

## pava_rulez

Hi guys,

I'm running an Apache 2.0.54 with good results. I would like to add PHP support to my webserver, what I already did in a previous installation, but this time I would like to be able to host some PHP pages which need to interact with a SQL Server 2000. I've tried to do an

```
USE="mssql -nls mysql odbc" emerge php mod_php
```

and this attempt failed when I was emerging freetds. So I retried without the Odbc flag enabled and the emerge actually got right. I changed file /etc/conf/apache2 and apache2.conf so Apache can use Php and restarted Apache. But when I try to see a PHP page on my browser nothing happens. I took a look at apache logs and I saw such a message:

```

PHP Warning:  Function registration failed - duplicate name - mssql_connect in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_pconnect in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_close in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_select_db in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_query in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_free_result in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_get_last_message in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_num_rows in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_num_fields in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_fetch_field in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_fetch_row in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_fetch_array in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_fetch_object in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_data_seek in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_field_seek in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_result in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_min_error_severity in Unknown on line 0

PHP Warning:  Function registration failed - duplicate name - mssql_min_message_severity in Unknown on line 0

PHP Warning:  mssql:  Unable to register functions, unable to load in Unknown on line 0

[Thu Jun 30 11:47:07 2005] [notice] Apache/2.0.54 (Gentoo/Linux) PHP/4.3.11 mod_ssl/2.0.54 OpenSSL/0.9.7e configured -- resuming normal operations

```

What did I miss? I can't seem to find a way out  :Crying or Very sad: 

----------

## beandog

What are your other USE flags?

----------

## pava_rulez

 *beandog wrote:*   

> What are your other USE flags?

 

Unfortunately in this moment I can't access the server. Gonna tell you tomorrow... thanks  :Wink: 

----------

## beandog

Ok, either way just make sure freetds is NOT in your USE flags.

If you use "odbc mssql -freetds" it should work.

----------

## pava_rulez

 *beandog wrote:*   

> Ok, either way just make sure freetds is NOT in your USE flags.
> 
> If you use "odbc mssql -freetds" it should work.

 

Thanks, tomorrow I'm gonna try. I'll let you know...

----------

## pava_rulez

Ok, emerge was successful. Php works properly, but when I try to connect to Sql Server I get this

```
Warning: mssql_connect(): message: Login failed for user 'User'. Reason: Not associated with a trusted SQL Server connection.

Warning: mssql_connect(): Unable to connect to server: ServerName in /var/www/localhost/...

```

How can I solve?

EDIT: BTW, thanks beandog!

----------

## beandog

I actually havent used mssql_connect much to connect to my databases.  I prefer PEAR's DB class myself.  Most likely you already have it installed, but your php.ini isn't setup to use it.  But, it looks like php is connecting just fine to the server, but that your SQL server is throwing some kind of authentication error.

If you want to use pear, here's what you would need to do:

Edit php.ini (probably /etc/php/apache2-php4/php.ini ), and look for include_path variable.

Set it to this if it isn't already:

```
.:/usr/lib/php
```

If you do have to change the php.ini, restart apache.  Then make sure that DB is installed (again, should be, by default)

```
pear list
```

Make a page that creates a DB connection using the pear class:

```
<?

require_once 'DB.php';

$dsn = array(

   'phptype' => 'mssql',

   'username' => 'beandog',

   'password' => '123',

   'hostspec' => 'localhost',

   'database' => 'master'

);

$options = array(

   'debug' => 2,

   'portability' => DB_PORTABILITY_ALL

);

$db =& DB::connect($dsn, $options);

if (PEAR::isError($db)) {

    die($db->getMessage());

}

?>
```

And see what that tells you.  If it doesn't connect, it should give you a good error to go off of.

For more docs on PEAR: :Very Happy: B see this: http://pear.php.net/manual/en/package.database.db.php

and here's their example of making a connection: http://pear.php.net/manual/en/package.database.db.intro-connect.php

----------

## pava_rulez

Still no chance to connect with mssql_connect. But I've read in other posts that freedts is mandatory to make the connection. So, have I got to emerge it or not?

----------

## beandog

It should be a dependency, although I'm not really sure if its actually used or not in the php libraries.    So, yes, go ahead and emerge it with both mssql and odbc as your USE flags to play it safe.

----------

## phenxor

cheers beandog, your pear/DB script worked a charm  :Smile: 

Integrated it with Argus (argus.tcp4me.com) to monitor a bunch of MSSQL & MSDE servers here.

----------

## B.Rock

I seem to be having this very same problem. 

my package.use has:

dev-php/mod_php gd hardenedphp imagemagick imap java jpeg ldap mysql png xml xml2 zlib mssql odbc -berkdb -freedts

Everytime I start Apache i get:

PHP Warning:  Function registration failed - duplicate name - mssql_fetch_row in Unknown on line 0

Any ideas?

----------

## B.Rock

 *B.Rock wrote:*   

> I seem to be having this very same problem. 
> 
> my package.use has:
> 
> dev-php/mod_php gd hardenedphp imagemagick imap java jpeg ldap mysql png xml xml2 zlib mssql odbc -berkdb -freedts
> ...

 

believe it or not.. -freedts and -freetds are not the same.. once i fixed that glaring typo.. my problems went away

----------

