Jump to content

Another n00bish PHP SQL question -_-


riT-k0MA

Recommended Posts

Hi again.

 

I learn new code best by getting an example from somewhere and studying it. It's probably not the best way nut it works for me.

Unfortunately, if the example code doesn't work I have no idea how to fix it.

 

I got this from here

 

<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}

/* Define the query. */
$tsql = "SELECT ProductID,
                UnitPrice,
                StockedQty 
         FROM Purchasing.PurchaseOrderDetail
         WHERE StockedQty < 3 
         AND DueDate='2002-01-29'";

/* Execute the query. */
$stmt = sqlsrv_query( $conn, $tsql);
if ( $stmt )
{
     echo "Statement executed.\n";
} 
else 
{
     echo "Error in statement execution.\n";
     die( print_r( sqlsrv_errors(), true));
}

/* Iterate through the result set printing a row of data upon each
iteration.*/
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
     echo "ProdID: ".$row[0]."\n";
     echo "UnitPrice: ".$row[1]."\n";
     echo "StockedQty: ".$row[2]."\n";
     echo "-----------------\n";
}

/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>

 

Obviously I changed the DB name and fields and datatypes.

 

It worked perfectly fine yesterday.

I tried to use a modified version of it this morning and it didn't work.

I then tried the origional (slightly modified) version of the code. That didn't work.

 

Both times the actual PHP code shows after " $connectionInfo = array( "Database"=> "  no matter what's in front of the >  ???

 

I really have no clue about what's going on and would be greatly enlightened and appreciative if someone could point out the fup.

 

many Thanks in advance

riT-k0MA

Link to comment
https://forums.phpfreaks.com/topic/148736-another-n00bish-php-sql-question-_/
Share on other sites

I learn new code best by getting an example from somewhere and studying it. It's probably not the best way nut it works for me.

Unfortunately, if the example code doesn't work I have no idea how to fix it.

 

That is indeed the biggest problem with simply copying and pasting code.

 

There are no such functions as all these sqlsrv* functions built into php. Have you defined them somewhere?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.