|
Posted by Manish on 08/22/06 04:54
try using global keyword ...
function open(){
global $dbhost;
global $dbuser;
global $dbpasswd;
global $dbname;
$this -> db = new sql_db($dbhost , $dbuser , $dbpasswd , $dbname ,
false);
if( !$this -> db -> db_connect_id )
{
die( "Could not connect to the database" );
}
}
.... make sure the file config.php is included before the file in which
the function open() is defined.
if you don't want to use global keyword then, declare the variable in
config.php as,
define('dbhost', 'somehost');
define('dbuser', 'someuser');
define('dbpasswd', 'somepassword');
define('dbname', 'somedb');
and in function open(), use them as (without $ sign)
$this -> db = new sql_db(dbhost , dbuser , dbpasswd , dbname , false);
Thanks.
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'] );
> }
> }
> }
>
> ?>
[Back to original message]
|