Jump to content

include file for db connection does not seem to be working


alanl1
Go to solution Solved by Kingy,

Recommended Posts

Hi Professionals

 

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

 

<?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 "<option value=";
echo "'".$row['software_manufacturer']."'";
echo ">";
echo $row['software_manufacturer'];
echo "</option>";

}

sqlsrv_free_stmt( $stmt);

?>
</select>
  <input type="submit" value="Search">
</br></br>
</form>
</body></html>

 

 

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 "<option value=";
echo "'".$row['software_manufacturer']."'";
echo ">";
echo $row['software_manufacturer'];
echo "</option>";

}

sqlsrv_free_stmt( $stmt);

?>
</select>
  <input type="submit" value="Search">
</br></br>
</form>
</body></html>

 

 

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));
}

?>

 

 

Any Ideas

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.