cannot get included dbconnection file to work

Hi Professionals

I have the following php file which works and returns data from the database

[php]

<?php $server='d3licsql02'; $connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "secret"); //connect to DB $conn=sqlsrv_connect($server,$connectinfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT distinct software_manufacturer FROM softusecomp"; $stmt = sqlsrv_query( $conn, $sql); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { echo ""; echo $row['software_manufacturer']; echo ""; } sqlsrv_free_stmt( $stmt); ?>   

I have changed this to two seperate files below which do not work

<?php include('ConnectDB'); $sql = "SELECT distinct software_manufacturer FROM softusecomp"; $stmt = sqlsrv_query( $conn, $sql); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { echo ""; echo $row['software_manufacturer']; echo ""; } sqlsrv_free_stmt( $stmt); ?>   

ConnectDB.php

<?php $server='d3licsql02'; $connectinfo=array("Database"=>"TestData", "UID" => "sa", "PWD" => "secret"); //connect to DB $conn=sqlsrv_connect($server,$connectinfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } ?>

[/php]

Any Ideas

I cannot seem to get this file
ConnectDB.php

to include and connect to the database

you got:
[php]
include(‘ConnectDB’);
[/php]

it should be:
[php]
include(‘ConnectDB.php’);
[/php]

should’nt it be?

no that doesnt work either

can you post the error displayed in you browser?

Hi All

I have managed to get this working. I was including the php file with the <?php ?> when i should have included this above my page code EG include <“ConnectDB.php”> then the page code<?php bla bla bla

thanks anyway guys

Sponsor our Newsletter | Privacy Policy | Terms of Service