Page 1 of 1

PHP MSSQL and GLOBALS or SESSIONS

Posted: Wed Oct 12, 2011 2:05 pm
by laural

Code: Select all

<?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: Select all

	$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,

}

);	
}
I know that the code above does not have the correct syntax, I was more trying to show what I needed to accomplish... I want to create the variables in either a GLOBAL list or a list of SESSIONS populated from an mssql table... any help would be greatly appreciated!

Re: PHP MSSQL and GLOBALS or SESSIONS

Posted: Wed Oct 12, 2011 9:41 pm
by laural
SOLVED IT! I used SESSIONS - thanks anyway :)

Code: Select all

$tsql2 = "SELECT term, native_term FROM [mydb].[dbo].[terms] 
WHERE 
	(id_language='$id_language');";

	$params2 = array();
	$options2 =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

	/* Execute the query. */
	$stmt2 = sqlsrv_query($conn, $tsql2, $params2, $options2);
	if( $stmt2 === false ) { die( print_r( sqlsrv_errors(), true )); }

	$row_count = sqlsrv_num_rows( $stmt2 );

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

while( $row = sqlsrv_fetch_array( $stmt2, SQLSRV_FETCH_ASSOC) ) {

				$term=$row["term"];
				$native_term=$row["native_term"];

				$_SESSION[$term]=$native_term;
}


				}