简体   繁体   中英

FileMaker SQL queries via ODBC Table doesn't return a result

I have this seriously strange issue. I have 4 tables in a FileMaker 12 file: Issues, Articles, FMBM, Ads. I have 2 methods in my results class, one writes a series of serial IDs to each of these tables, the other queries those tables. The method that writes the serial ID's works perfectly. The method that queries the tables works for 3 of the 4 tables (Articles, FMBM, Ads) but returns no result set for Issues.

I have checked permissions, but as this is the admin user, it has full access to all and there are no table specific or layout specific restrictions (again, it's the admin). Oddly enough, I thought maybe it's the query, but when I run "SELECT * FROM Issues" in my ODBC Query Tool, it returns the appropriate results. It's just baffling to me that the setKeys() method works perfectly but the view method ONLY fails on Issues.

The Model:

class Application_Model_Results {

    public $keys;
    public $odbc;
    public $comp = array('Issues', 'Articles', 'Ads', 'FMBM');
    public $existing = array();

    function setKeys() {
        $this->odbc = 'Migrator';
        $obj = new Application_Model_Utilities();
        $obj->name = $this->odbc;
        $config = $obj->getElements();
        $conn = odbc_connect($this->odbc, $config['user'], $config['password']);
        if (!$conn) {
            exit("Connection failed: -> " . $this->odbc);
        }
        foreach ($this->comp as $c) {
            $sql = "SELECT Serial_ID FROM " . $c;
            $rs = odbc_exec($conn, $sql);
            if (!$rs) {
                exit("Error in SQL");
            }
            while (odbc_fetch_row($rs)) {
                $this->existing[] = odbc_result($rs, 'Serial_ID');
            }
            if (in_array(true, $this->keys[$c])) {
                foreach ($this->keys[$c] as $v) {
                    if (!in_array($v, $this->existing)) {
                        $iSql = "INSERT INTO " . $c . "(Serial_ID) VALUES('$v')";
                        odbc_exec($conn, $iSql);
                        $obj->output = 'Inserted Serial_ID: ' . $v . ' into table ' . $c;
                        $obj->logger();
                    }
                }
            }
        }
    }

    public function getResults($table) {
        $this->odbc = 'Migrator';
        $obj = new Application_Model_Utilities();
        $obj->name = $this->odbc;
        $config = $obj->getElements();
        $conn = odbc_connect($this->odbc, $config['user'], $config['password']);
        if (!$conn) {
            exit("Connection failed: -> " . $this->odbc);
        }
        $sql = "SELECT * FROM " . $table;
        $rs = odbc_exec($conn, $sql);
        while (odbc_fetch_row($rs)) {
            $results[odbc_result($rs, 'Serial_ID')] = odbc_fetch_array($rs);
        }
        return $results;
    }

}

The Controller:

public function viewAction()
    {
        $results = new Application_Model_Results();
        $result = $results->getResults('Issues');
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($result);
        $paginator->setItemCountPerPage(1);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
    }

Note: If scrap the view code, and just write:

<?php 

$conn = odbc_connect('Migrator', 'admin', '********');
$sql = "SELECT * FROM Issues";
$rs = odbc_exec($conn, $sql);
while(odbc_fetch_row($rs)){
    print_r(odbc_result_all($rs));
}

I get no rows returned.

EDIT:

Culprit has been found:

while (odbc_fetch_row($rs)) {
    $results[odbc_result($rs, 'Serial_ID')] = odbc_fetch_array($rs);
}

Now, I am working on a solution that grabs each result row and pushes it to an associative array, the problem is, on the view, I need to dump everything, not have to use odbc_result($rs, ) for every single field.

Finally, my nightmare is over:

public function getResults($table) {
        $obj = new Application_Model_Utilities();
        $obj->name = $this->odbc;
        $config = $obj->getElements();
        $conn = odbc_connect($this->odbc, $config['user'], $config['password']);
        if (!$conn) {
            exit("Connection failed: -> " . $this->odbc);
        }
        $sql = "SELECT * FROM " . $table;
        $obj->output = 'Running query: ' . $sql;
        $obj->logger();
        $rs = odbc_exec($conn, $sql);
        $obj->output = 'Results found: ' . odbc_num_rows($rs);
        $obj->logger();
        $results = array();
        $i = 1;
        while(odbc_fetch_row($rs)){
            $results[] = odbc_fetch_array($rs, $i);
            $i++;
        }


        return $results;
    }

This returns an associative array that I can actually loop through.

NOTE: in this instance, any use of odbc_fetch_array, odbc_fetch_object, odbc_fetch_into, unless I forced the odbc_fetch_array to have a row value, would only reutrn every other result, not all results and then would die on the view unless I specifically called for a field value, and even then, the same value persisted across all paginated records.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM