Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-26-2008, 01:13 PM
Member
 
Join Date: Feb 2008
Posts: 48
Question ZF Doubts on Location & DB classes

I hv created the Table Class and saved the table class under library->Tables(new folder)->user.php.

class User extends Zend_Db_Table_Abstract
{
protected $_schema = 'zfwork';// DB name
protected $_name = 'user';// Table name
protected $_primary = 'ID';// primary key setting.
}
Here do i need to give the other fields(email,phone) also? or not required?
-----------------------

And added the below code to do autoloading of required class.
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload(); IN the bootstrap file(index.php).
Then the below statment is required for table operation?
"require_once 'Zend/Db/Table/Abstract.php';"

-----------------------

While using the below code in the controller page (UserController.php) in the listAction() function, i am not getting the output. Can you plz tell me where is the error and whats the problem? Because its confusing.
$table = new Tables_User();
$users = $table->find(2);
print_r($users);

-----------------------

One more thing is, for DB connection i am using the following code and connected successfully. My question is, if i hv the DB connection then why should i use a separate "Table Classes" like above. And plz tell me the importance of this also.
$options = array('host'=> 'localhost',
'username'=> 'developer',
'password'=> 'success',
'dbname'=> 'test'
);
$db = Zend_Db::factory('Pdo_Mysql', $options);

-----------------------

Please explain the above DB & Table functionality questions with some example.



-Mugesh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 04:18 AM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
Here do i need to give the other fields(email,phone) also? or not required?
This is not required.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 04:19 AM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
While using the below code in the controller page (UserController.php) in the listAction() function, i am not getting the output. Can you plz tell me where is the error and whats the problem? Because its confusing.
$table = new Tables_User();
$users = $table->find(2);
print_r($users);
It should be:
PHP Code:
$table = new User();
$query $table->find(2);
$this->view->$query $query
Then in your view script:
PHP Code:
<?php
    print_r
($this->$query);
?>
Try that. Does it work?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 04:24 AM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Read up on Zend_Db_Table. It is not necessary to use this component, but I like using it.

Zend_Db_Table
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 06:55 AM
Member
 
Join Date: Feb 2008
Posts: 48
Question

How to print the mysql error ? If direct php , we can use mysql_error(). But i dont know how to find here.?? plz reply as soon as possible.

-mugesh.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:20 PM.