riT-k0MA Posted March 10, 2009 Share Posted March 10, 2009 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 Quote Link to comment Share on other sites More sharing options...
waynew Posted March 10, 2009 Share Posted March 10, 2009 Are you sure that this is in a .php file? Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 Title of te link: How to: Retrieve Data as an Array (SQL Server 2005 Driver for PHP) Unless m$ have screwed up, which is highly probable Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 I took a break and viewed the code again. I think that it might be picking up the > as a "close tag" and viewing the rest as html. IF that's the case, how could I fix it? Quote Link to comment Share on other sites More sharing options...
trq Posted March 10, 2009 Share Posted March 10, 2009 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? Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 No. I just copied and pasted the code, thinking it was standalone. Quote Link to comment Share on other sites More sharing options...
trq Posted March 10, 2009 Share Posted March 10, 2009 Then I would suggest that could be your problem. Still seems odd though. However, no matter how you look at it that code is useless without those functions and will need to be rewritten using a proper (existing) database abstraction layer. Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 Ok. I'll take another look at it and see if I can do anything. Otherwise I'll have to search for another DB example to use. Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted March 10, 2009 Share Posted March 10, 2009 Otherwise I'll have to search for another DB example to use. I would suggest http://php.net/manual, any MS website probably isn't th ebest place to learn php. Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 ok, thanks Quote Link to comment Share on other sites More sharing options...
riT-k0MA Posted March 10, 2009 Author Share Posted March 10, 2009 I'm using the PHP docuentation, though as far as I can see, it's or nromal SQL authentication. Unfortunatly I have to use Windows Authentication, which is why I was using the msdn stuff. Looks like I'll have to try and muddle through everything Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.