You are here: Re: cannot get the values specified inside of another file using include or require_once « PHP Programming Language « IT news, forums, messages
Re: cannot get the values specified inside of another file using include or require_once

Posted by Jerry Stuckle on 08/22/06 10:46

mich dobelman wrote:
> I cannot reference the values in side of config.php
> $dbhost,$dbuser ,$dbpasswd ,$dbname why?
> <?php
>
> require_once('includes/db.php'); //db connection functions
> require_once('config.php'); //db connection parameters
>
>
> class DBRegion{
> var $db;
> function DBRegion(){
>
> }
>
> function open(){
>
> $this -> db = new sql_db($dbhost , $dbuser , $dbpasswd , $dbname ,
> false);
>
> if( !$this -> db -> db_connect_id )
> {
> die( "Could not connect to the database" );
> }
> }
>
> function close(){
>
> $this -> db -> sql_close();
>
> }
>
> function updateName( $id, $name ){
>
> $sql = "update web_coupon_region set name = '$name' where id = $id ";
>
> $result = $this -> db -> sql_query( $sql ) or die( "Coun't proceed with
> the following sql: ".$sql );
>
> }
>
> //UPDATE `web_coupon_region` SET `mdate` = '2006-08-16 05:05:55' WHERE
> `id` = '1' LIMIT 1 ;
>
> function updateModDate( $id, $date )
> {
>
> //$this -> db = new sql_db($dbhost , $dbuser , $dbpasswd , $dbname ,
> false);
> $sql = "update web_coupon_region set mdate = '$date' where id = '$id'";
>
> $result = $this -> db -> sql_query( $sql ) ;
>
> if(!$result ){
> $error = $this -> db -> sql_error();
> die( "Coun't proceed with the following sql: ".$error['message'] );
> }
> }
> }
>
> ?>
>
>

IMHO it's better to pass the parameters to the function, i.e.

function open($host, $user, $passwd, $name){

$this -> db = new sql_db($host , $user , $passwd , $name ,
false);

if( !$this -> db -> db_connect_id )
{
die( "Could not connect to the database" );
}
}


....

$dbregion = new $DbRegion();
$dbregion -> open($dbhost, $dbuser, $dbpasswd, $dbname);

This gives you more flexibility in your code. Right now you may only
use one database on one host, for instance. But what about another
system - or later?

Or even now, you might have one user with limited privileges for the
general public, and another user with more privileges for admin users.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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