why do I get undefined variable error while trying to access a global vairable from a function?
<p>I've written a code like following in php</p>

<pre><code>&lt;?php

  global $server ,$username ,$password ,$database; 
  $server ="localhost:3306";
  $username="user";
  $password="pass";
  $database="dbname";

  function connectToDB()
  {
     mysql_connect($server,$username,$password) or die ("can't connect to server");
     mysql_select_db($database) or die ("can't select database");
  }
?&gt;
</code></pre>

<p>but I'm not able to access those variables inside my function what is my problem?</p>

<p>even without the global keyword I'm not able to access those variables.</p>
