Sharing ThinkPHP3.2 Query Solution _php Example

Source: Internet
Author: User
No nonsense, directly to everyone to paste the code, the code is very simple, are more common SQL statements, the specific content please see below.

CREATE TABLE ' Test_avatar ' (' uid ' int (one) unsigned NOT null default ' 0 ', ' Avatar ' varchar (255) NOT null default ', PRIMA RY KEY (' uid ')) Engine=myisam DEFAULT charset=utf8;insert into ' Test_avatar ' VALUES (1, './uploads/admin.jpg '); CREATE TABLE ' Test_pro ' (' id ' int (one) unsigned not null auto_increment, ' uid ' int (one) unsigned not null DEFAULT ' 0 ', ' nam E ' varchar (255) Not NULL default ", PRIMARY KEY (' id ')) engine=myisam default Charset=utf8;insert into ' Test_pro ' VALUES (1, 1, ' Product 1 '), (2,1, ' Product 2 '); CREATE TABLE ' Test_user ' (' id ' int (one) unsigned not null auto_increment, ' username ' varchar (a) NOT null DEFAULT ' ', ' tel ' Int (one) unsigned not NULL default ' 0 ', PRIMARY KEY (' id ')) engine=myisam the default Charset=utf8;insert into ' Test_user ' VA Lues (1, ' admin ', 110);

As in three tables: User Avatar table, product table, user table

How do I build relationships in the model?

Class Promodel extends relationmodel{protected $_link=array (' Avatar ' =>array (' Mapping_type ' =>self::has_one, ' Class_name ' + ' Avatar ', ' foreign_key ' = ' uid ', ' mapping_fields ' = ' Avatar ', ' as_fields ' = ' Avatar ',  )}

Tried to use Has_one, belongs_to, Has_many, many_to_many are not, ask the big God pointing

------to solve the idea----------------------

Model to establish the ProModelModel.class.php

Class Promodelmodel extends ViewModel {public  $viewFields = Array ('   Test_avatar ' =>array (' id ',...),   ' Test_pror ' =>array (' id ',... ' _on ' = '),      ' Test_pror ' =>array (' id ',... ' _on ' = ')  ; }

The problems and solutions of SQL statements in thinkphp

I ask, in thinkphp, the data table has a field, the contents of the field is {1,2,3,4,5}

So how do you compare the ID value in the SQL statement to the content in the field?

------to solve the idea----------------------

Use fuzzy query.

$where = Array (' The field ' =>array (' like ', '% '. $ID. '%'));
  • Related Article

    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.