gpt4 book ai didi

mysql - 从 mysql 表中获取 Data_type

转载 作者:可可西里 更新时间:2023-11-01 06:58:24 25 4
gpt4 key购买 nike

我使用这段代码:

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

但是在 echo 之后,它返回 1。但是当我在 phpmyadmin sql 中运行它时,它返回列的 data_type

我想要 Mysql 表列的 data_type(我正在使用 Wordpress)。

最佳答案

you can simply get the datatype as below. where ever you like . you can change different data_type by changing the value of "$tableName" and "$column_name" below

<?php
global $wpdb;$prefix=$wpdb->prefix;
$tableName=$prefix.'posts';
$column_name='post_title';
echo $sql="SELECT data_type FROM information_schema.columns WHERE table_name = '$tableName' AND column_name = '$column_name' ";
$dataType = $wpdb->get_var($sql);
echo $dataType;?>

关于mysql - 从 mysql 表中获取 Data_type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38844591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com