Connection error php and dbisam

0

My problem is the following I am trying to connect to a dbisam database via php but I have not been able to make a query and download the ODBC driver for dbisam, these are the errors that they give me:

  

Warning: odbc_connect (): in C: \ xampp \ htdocs \ DBISAM.php on line 13

     

Warning: odbc_exec () expects parameter 1 to be resource, boolean given in C: \ xampp \ htdocs \ DBISAM.php on line 39

     

Warning: odbc_fetch_array () expects parameter 1 to be resource, null given in C: \ xampp \ htdocs \ DBISAM.php on line 41

this is my complete script

 <?php

class DBISAM {

    // set folder here
    static $folder = "C:/xampp/htdocs/Data";
    static $db;

    // Connect to ODBC source
    public static function Connect() {

        $db = odbc_connect("DRIVER={DBISAM 4 ODBC Driver};ConnectionType=Local;CatalogName=".self::$folder.";","admin","");
        self::$db = $db;
        return $db;
    }

    // Escape a string
    public static function Escape($data) {
        if ( !isset($data) or empty($data) ) return '';
        if ( is_numeric($data) ) return $data;

        $non_displayables = array(
            '/%0[0-8bcef]/',            // url encoded 00-08, 11, 12, 14, 15
            '/%1[0-9a-f]/',             // url encoded 16-31
            '/[\x00-\x08]/',            // 00-08
            '/\x0b/',                   // 11
            '/\x0c/',                   // 12
            '/[\x0e-\x1f]/'             // 14-31
        );
        foreach ( $non_displayables as $regex )
        $data = preg_replace( $regex, '', $data );
        $data = str_replace("'", "''", $data );
        return $data;
    }

    // Get all data from an ODBC query, into an array
    public static function GetAll($query,$key="") {
        $res = odbc_exec(self::$db,$query);
        $result = array();
        while($row=odbc_fetch_array($res)) {
            if ($key)
                $result[$row[$key]] = $row;
            else
                $result[] = $row;
        }       
        return $result;
    }


    // Run an ODCB query
    public static function Query($query) {
        $res = odbc_exec(self::$db, $query);
        return $res;
    }

}
?>
    
asked by alexander123 31.03.2016 в 15:23
source

2 answers

1

The call to odbc_connect is failing, check that you have the parameters correctly (path, user, password, etc.). To rule out errors you can try to establish the connection from Excel for example.

    
answered by 04.04.2016 в 15:31
0

You are defining your Connect() function but you are not calling it to define the connection parameters. Simply call it before doing odbc_exec() so that $db has the appropriate value:

Connect();
 $res = odbc_exec(self::$db,$query);
    
answered by 05.04.2016 в 22:02