Re: Global variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now if in PMConnect() I return $link(see example below); it works for me.

<?php
function PMConnect() {
global $dbservertype, $servername, $dbusername, $dbpassword, $dbname, $link;

    $link = mssql_connect("$servername", "$dbusername", "$dbpassword");
    if (!$link) {
sprintf($Message, "At %d in %s Could not connect to %s at %s as %s",__LINE__, __FILE__, $dbname, $servername, $dbusername);
        trigger_error(E_USER_ERROR, $Message);
        }
    if (!(mssql_select_db("$dbname", $link))) {
sprintf($Message, "At %d in %s Could not select %s at %s as %s",__LINE__, __FILE__, $dbname, $servername, $dbusername);
        trigger_error(E_USER_ERROR, $Message);
        }
    echo "In PMConnect() link = $link<br>";
    return $link;
    }
?>

Alf Stockton wrote:
The following scenario has me confused. In my main program I have:-
<?php
$link = '';
.....snip......
?>
in an included function I have
<?php
function PMConnect() {
global $dbservertype, $servername, $dbusername, $dbpassword, $dbname, $link;

    $link = mssql_connect("$servername", "$dbusername", "$dbpassword");
    if (!$link) {
sprintf($Message, "At %d in %s Could not connect to %s at %s as %s",__LINE__, __FILE__, $dbname, $servername, $dbusername);
        trigger_error(E_USER_ERROR, $Message);
        }
    if (!(mssql_select_db("$dbname", $link))) {
sprintf($Message, "At %d in %s Could not select %s at %s as %s",__LINE__, __FILE__, $dbname, $servername, $dbusername);
        trigger_error(E_USER_ERROR, $Message);
        }
    echo "In PMConnect() link = $link<br>";
    }
?>
and here the echo shows that $link contains data but now in another included function I have
<?php
function GetActive($Datum) {
    global $link;
    echo "In GetActive() link = $link<br>";
.....snip......

this echo shows that $link is empty.

NB. All my functions are contained within .inc files that are incorporated via something similar to include('includes/PMConnect.inc');
What am I misunderstanding ?



--
Regards,
Alf Stockton		www.stockton.co.za

Tempt not a desperate man.
		-- William Shakespeare, "Romeo and Juliet"

My email disclaimer is available at www.stockton.co.za/disclaimer.html

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux