phpgroupware-developers
[Top][All Lists]
Advanced

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

Re: [Phpgroupware-developers] connect to and query other databases


From: heiko . schwarzenberg
Subject: Re: [Phpgroupware-developers] connect to and query other databases
Date: Wed, 22 May 2002 12:33:12 +0200

> Hello all,
> 
> Can somebody tell me how I can use functions from the phpgwapi to connect to 
> another database
> and do queries on it? At the moment I use direct mysql_query and connect 
> functions. I know
> this is a bad thing to do.
> 
> Maybe you can give me a phpgw equal to the following:
> 
>    $conn=mysql_pconnect($localhost,$user,$database);
>    mysql_select_db($database, $conn);

if you use the api-functions of phpgw, you don't need to connect manually or 
choose 
the right database. phpgw takes care for that :-)

>    $SQL='SELECT * FROM '. $table . ' WHERE';
>    $result=mysql_query($SQL,$connection);

the database functions are available globally through $GLOBALS['phpgw']->db
a short example:

$this->db = $GLOBALS['phpgw']->db;
$sql = 'SELECT * FROM'.$table;
$this->db->query($sql);

while($this->db->next_record())
{
  //do something
  echo $this->db->f('fieldname');
}

short summary of most-used commands:

GLOBALS['phpgw']->db->query($sql) : does the query
GLOBALS['phpgw']->db->limit_query($sql, $start,__LINE__,__FILE__,$limit) 
:returns a limited result from start to limit
GLOBALS['phpgw']->db->next_record(): walks through the result set
GLOBALS['phpgw']->db->f('fieldname') : gets the value of the given field

for a better understanding, you should take a look at 
phpgwapi/inc/class.db_mysql.inc.php and also at the source of other phpgw-apps.

hope that helps for getting a first glance...
heiko






reply via email to

[Prev in Thread] Current Thread [Next in Thread]