You are here: Re: QuickFom question RESOLVED « PHP Programming Language « IT news, forums, messages
Re: QuickFom question RESOLVED

Posted by Markus Ernst on 08/11/06 12:49

IchBin schrieb:
> The api specs states for a 'loadQuery' that I should user either
> an existing DB connection or a valid dsn for the first parameter. Well I
> got in to my head to use the $dsn var. Well I kept that var in another
> php file 'config.php'. So come time to use it, even having an include
> for that file, the running php script could not find it.

Just a guess - the missing $dsn variable could be a namespace issue.
Variables defined inside a function or a class will not be available in
the global namespace. For example, if you connect via a function like:

<?php
function &connect_db($host, $user, $pass) {
$dsn = array('host'=>$host, 'user'=>$user, 'pass'=>$pass);
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db('myhost', 'myuser', 'mypassword');
?>

$dsn is not set in the global namespace. Or the include happens inside a
function or class:

<?php
function &connect_db() {
include_once('config.php'); // contains the $dsn declaration
include_once('DB.php');
$db =& DB::connect($dsn);
return $db;
}
$db =& connect_db();
....
do_something($dsn); // I think that won't work
....
include('config.php');
do_something_else($dsn); // I think that won't work either
?>

I assume that also here the scope of $dsn is limited to connect_db(),
and include_once() prevents config.php from being included again.

--
Markus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация