View Single Post
Old 10-12-2011, 05:43 PM   PM User | #1
laural4705
New to the CF scene

 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
laural4705 is an unknown quantity at this point
PHP, MSSQL and $GLOBALS

Code:
<?php

$GLOBALS['text']=array (
	'foo1' => 'ValueOne',
	'foo2' => 'ValueTwo',
	'foo3' => 'ValueThree'
);

?>
Here is my global array, what I want is to do a find on my mssql database to pull in the global values from a table. I am trying to figure out if there is a way to do that... here is what I have (that gives errors) - I have done many revisions of the code and can't seem to get where there are no errors. Thanks for any help offered!

Code:
	$serverName = "MYSERVER";
	$connectionInfo = array( "Database"=>"MYDB", "CharacterSet" => "UTF-8","UID" => "MYUID", "PWD" =>"MYPWD");
	$conn = sqlsrv_connect( $serverName, $connectionInfo);

	if ( $conn === false ) {
		echo "Could not connect.<br>";
		die( print_r( sqlsrv_errors(), true));
	}

	$tsql1 = "SELECT term, native_term FROM [pwf].[dbo].[terms_data] 
WHERE 
	(id_language='$id_language');";

	$params1 = array();
	$options1 =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

	/* Execute the query. */
	$stmt1 = sqlsrv_query($conn, $tsql1, $params1, $options1);
	if( $stmt1 === false ) { die( print_r( sqlsrv_errors(), true )); }

	$row_count = sqlsrv_num_rows( $stmt1 );

	if ($row_count === false) {
   		echo "Error in retrieveing row count."; }
		
	elseif ($row_count > 0) {

$GLOBALS['text']=array (

		while( $row = sqlsrv_fetch_array( $stmt1, SQLSRV_FETCH_ASSOC) ) {
				$term=$row["term"];
				$native_term=$row["native_term"];

	$term => $native_term,

}

);	
}

Last edited by laural4705; 10-12-2011 at 05:46 PM.. Reason: Fixing my code tags...
laural4705 is offline   Reply With Quote