V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
yakczh
V2EX  ›  MySQL

如果两个表有同名的字段,根据给定的字段,能找到是哪个表吗?

  •  
  •   yakczh · Jul 24, 2015 · 2245 views
    This topic created in 3934 days ago, the information mentioned may be changed or developed.

    比如两个表 posts commments
    其中都有字段 create_time
    $field='create_time';

    function test($filed){

    }

    能否根据字段名找出是哪个表?

    phx13ye
        1
    phx13ye  
       Jul 24, 2015
    use information_schema;

    SELECT * FROM COLUMNS WHERE COLUMN_NAME = '$filed';
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 18:59 · PVG 02:59 · LAX 11:59 · JFK 14:59
    ♥ Do have faith in what you're doing.