mysql多表字段名重复的情况
CREATE TABLE `card` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `json_str` varchar(100) NOT NULL, `f` decimal(10,2) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=574 DEFAULT CHARSET=utf8 CREATE TABLE `card2` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `json_str` varchar(100) NOT NULL, `f` decimal(10,2) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=574 DEFAULT CHARSET=utf8
mysql命令行下的执行结果:
相同的字段名会按相同的显示
navicate下的执行结果
相同的字段名,后面的会链接一个编号(编号依次递增)
pdo方式获取数据
$dsn = "mysql:host=127.0.0.1;port=3306;dbname=test"; $opts = array(PDO::ATTR_AUTOCOMMIT=>0, PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_AUTOCOMMIT=>0); try { $pdo = new PDO($dsn, 'root', '', $opts); }catch(PDOException $e){ echo $e->getMessage(); } //获取结果 $stmt = $pdo->prepare("SELECT * FROM `card` as a left join card2 as b on a.id = b.id"); $stmt->execute(); //方式1 $data = $stmt->fetchAll(pdo::FETCH_ASSOC); ee($data);
注意:后面的会覆盖前面的