views:

40

answers:

2

i have just finished my first site built with zend framework and all works great on my local machine.

then i uploaded it to the server (godaddy) and all works except any connection my models do with the database. i have made a connetion to the database with regular PDO with the credentials in my application.ini and it worked, and i can interact with the model if its not returning anything from the database. (and again all the models work great on my local machine).

my models looks like that:

class Default_Model_picture extends Zend_Db_Table_Abstract 
{

    protected $_name = 'pictures';

    protected $_primary = 'id';

    public function getPicturesByCategory($category)
    {

        $query = $this->select()->from(array('pictures'), array(
           'pictures.id', 'pictures.pic_name', 'pictures.pic_desc', 
           'pictures.pic_category', 'pictures.pic_date_added', 
           'pictures.pic_larger', 'pictures.pic_url'));

        $query->where('pic_category = ?', $category);
        $query->order('pic_date_added ASC');
        $result = $this->fetchAll($query);

        return $result;    
    }    
}

this is an example for a model, obviously i did not added lots of methods.

i have no idea what to do next.

A: 

I am assuming you set up the db connection correctly into $db. Afterwards you must set it as the default adapter for Zend_Db_Table.

Zend_Db_Table::setDefaultAdapter($db);

I am just assuming this is what went wrong. But it is a common problem, so I decided to go ahead and answer anyway.

naneau
hiin my application.ini it is set as the default adapter like so:resources.db.isDefaultTableAdapter = truebest regards
ron
A: 

Since your script works fine on your local machine, the first thing I check is if you have got the database connection params setup correctly in your application.ini

Try to write a test script that uses the pdo functions on itself (without zend framework). see if you get any errors at all

try {
    $dbh = new PDO('mysql:host=YOURHOST;dbname=YOURDBNAME', $YOURUSERNAME, $YOURPASSWORD);
    foreach($dbh->query('SELECT * from FOO') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
marsbomber
hias i said in my original question i did connected to the database with PDO in the regular way. not the zend way. and that test worked.the issue is to understand why the zend way does not work.best regards
ron