Zend_db_table_abstract uses zend_db_select and join, JoinLe

Source: Internet
Author: User
Today, let's talk about how to use some query statements in zend_db_table_abstract. If you need them, please refer to them.

Today, let's talk about how to use some query statements in zend_db_table_abstract. If you need them, please refer to them.

The Code is as follows:


--
-- Table structure 'charge _ logs'
--

Create table if not exists 'charge _ logs '(
'Id' int (11) not null AUTO_INCREMENT,
'Charge _ id' int (11) not null,
'Title' text not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 2;

--
-- The data in the table is stored in 'charge _ logs'
--

Insert into 'charge _ logs' ('id', 'charge _ id', 'title') VALUES
(1, 1, 'xxxxxxx ');

--
-- Table structure 'user _ charges'
--

Create table if not exists 'user _ charges '(
'Id' int (10) unsigned not null AUTO_INCREMENT,
'User _ id' int (10) not null,
'Charge _ type' int (3) not null,
'Charge _ subtype' int (3) not null,
'Charge _ credits 'int (3) not null,
'Buy _ date' timestamp not null default '2017-00-00 00:00:00 ',
'Valid _ to' timestamp not null default '2017-00-00 00:00:00 ',
'Next _ charge_date 'timestamp not null default '2017-00-00 00:00:00 ',
'Payment' varchar (50) not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 2;

--
-- Store the data in the table 'user _ charges'
--

Insert into 'user _ charges '('id', 'user _ id', 'charge _ type', 'charge _ subtype', 'charge _ credits ', 'Buy _ date', 'valid _ to', 'next _ charge_date ', 'payment') VALUES
(1, 1, 1, 1,100, '2017-09-09 00:00:00 ', '2017-09-16 00:00:00', '2017-00-00 00:00:00 ', 'paypal ');
Use query in zend_db_table_abstract

$ Select = $ this-> getAdapter ()-> select ();
$ Select-> from (array ('uc' => 'user _ charges '))
-> JoinLeft (array ('cl' => 'charge _ logs'), 'uc. id = cl. charge_id ', array ('title '))
-> Where ('uc. user_id =? ', $ Id );
Return $ this-> getAdapter ()-> fetchAll ($ select );
If Mapper is used, you can use

$ Select = $ this-> getDbTable ()-> getAdapter ()-> select ();
$ Select-> from (array ('uc' => 'user _ charges '))
-> JoinLeft (array ('cl' => 'charge _ logs'), 'uc. id = cl. charge_id ', array ('title '))
-> Where ('uc. user_id =? ', $ Id );

Return $ this-> getDbTable ()-> getAdapter ()-> fetchAll ($ select );
Output result

Array (1 ){
[0] => array (10 ){
["Id"] => string (1) "1"
["User_id"] => string (1) "1"
["Charge_type"] => string (1) "1"
["Charge_subtype"] => string (1) "1"
["Charge_credits"] => string (3) "100"
["Buy_date"] => string (19) "00:00:00"
["Valid_to"] => string (19) "00:00:00"
["Next_charge_date"] => string (19) "0000-00-00 00:00:00"
["Payment"] => string (6) "paypal"
["Title"] => string (7) "XXXXXXX"
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.