简体   繁体   中英

How to get attributes of columns from SQL query (PHP \ Phalcon \ PostgreSQL)

I have two tables: manager , order .

One manager has many orders.

How i can get columns types, which in SELECT, from query like this

SELECT m.name, o.date, o.phone
FROM manager m
LEFT JOIN order o ON m.id = o.manager_id

PostgreSQL 9.4

SELECT column_name , data_type ,character_maximum_length  FROM information_schema.columns WHERE table_schema = 'your_schema' AND table_name   = 'your_table';

From Phalcon you can use Model metadata.

$manager = new Manager();
$order = new Order();

$metadata = $model->getModelsMetaData();

var_dump($metadata->getDataTypes($manager));

You will get and array with each column name and the type as an integer.

array (size=3)
  'col1' => int 0
  'col2' => int 2
  ...
  'coln' => int 2

The integer is one of the TYPE_* constants from \\Phalcon\\Db\\Column .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM