[Cartoweb-users] Calling PEAR DB functions

Yves Jacolin yjacolin at free.fr
Sun Jan 7 05:00:38 EST 2007


Hello max,

Here an example :
The first function set up a dsn from public variable, create the sql command 
and use the second function to realise the command. The second, which will 
more interesting for you, realise the sql command. As you can see, you need 
to "require" the DB.php file and so you can access to all method for DB 
access.

Regards,

Y.

    private function tableExist($table) {
         $dsn=$this->dsn;
         $sql="SELECT * FROM geometry_columns WHERE f_table_name='$table'";
         //if numRow->0, layer doesn't exist.
         $res = $this->resquestDB($dsn,$sql,"1");
         return $res[0];
    }

    /**
     * Realise resquest
     */
      private function resquestDB($dsn,$sqlRequested,$count=0){
         //connect and realise request
        require_once 'DB.php';
        $options = array(
           'debug'       => 2,
           'portability' => DB_PORTABILITY_ALL,
        );

        $db =& DB::connect($dsn, $options);
        if (PEAR::isError($db)) {
            $this->Message .='Message Standard         : ' . 
$db->getMessage() . "\n";
            $this->Message .= 'Message DBMS/Utilisateur : ' . 
$db->getUserInfo() . "\n";
            $this->Message .= 'Message DBMS/Débogage   : ' . 
$db->getDebugInfo() . "\n";
            exit;
        }
        $res =& $db->query($sqlRequested);
        if($count){$nber=$res->numRows();}
        else{$nber="";}
        // Always verify that $res is not an error
        if (PEAR::isError($res)) {
           die($res->getMessage());
           $success=0;
        }
        else{$success=array($nber,$res);}
        //return 0 if error, result if correct
        return $success;
        $res->free();
        $db->disconnect();
      }
Le Vendredi 5 Janvier 2007 18:11, Max Ueda a écrit :
> Hi,
>
> I've been trying to call some PEAR functions at my
> plugins, with no success. How can I have access to the
> functions  getOne(),  getRow(),  getCol(),  getAssoc()
> and  getAll()?
>
> Thanks in advance,
>
> Max Ueda
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users

-- 
Yves Jacolin
-------------
http://yjacolin.gloobe.org
http://softlibre.gloobe.org



More information about the Cartoweb-users mailing list