Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch Data_type from mysql Table

I use this code:

select data_type from information_schema.columns where table_name = '$tableName' and column_name = '$column_name'

But after echo, it's returning 1. But when I run it in phpmyadmin sql it's returning data_type of column.

I want data_type of Mysql Table column (I'm using Wordpress).

like image 811
Mamunur Rashid Avatar asked Aug 09 '16 07:08

Mamunur Rashid


1 Answers

Try this in wordpress. You should use get_var() or get_row() method.

$wpdb->query() returns only (int|false) Number of rows affected/selected or false on error

$dataType = $wpdb->get_var("select data_type from information_schema.columns where table_name = '$tableName' and column_name = '$column_name' ");        
echo $dataType;exit;

Edited :

I have tried in my local like. you should try by setting these two varibale $tableName='wp_posts'; $column_name='post_title'; like below :

$tableName='wp_posts';
$column_name='post_title';
$data = $wpdb->get_var("select data_type from information_schema.columns where table_name = '$tableName' and column_name = '$column_name'"); 
echo $data;

Output

mediumtext
like image 200
Rakesh Sojitra Avatar answered Sep 28 '22 16:09

Rakesh Sojitra