检查列匹配条件。
原型
check_column( string $table_name, string $col_name, string $col_type, bool $is_null = null, mixed $key = null, mixed $default = null, mixed $extra = null )
描述
使用SQL DESC检索列的表信息。如果你对SQL语句返回的列信息进行更多研究,将有助于理解这些参数。传入null以跳过检查该条件。
参数
$table_name
(string)
(Required)
表名
$col_name
(string)
(Required)
列名
$col_type
(string)
(Required)
列类型
$is_null
(bool)
(Optional)
检查为空。
$key
(mixed)
(Optional)
关键信息
$default
(mixed)
(Optional)
默认值。
$extra
(mixed)
(Optional)
超值。
返回值
(bool)
是的,如果匹配的话。假,如果不匹配。
源文件
路径:wp-admin/install-helper.php
<?php
...
function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) {
global $wpdb;
$diffs = 0;
$results = $wpdb->get_results("DESC $table_name");
foreach ($results as $row ) {
if ($row->Field == $col_name) {
// Got our column, check the params.
if (($col_type != null) && ($row->Type != $col_type)) {
++$diffs;
}
if (($is_null != null) && ($row->Null != $is_null)) {
++$diffs;
}
if (($key != null) && ($row->Key != $key)) {
++$diffs;
}
if (($default != null) && ($row->Default != $default)) {
++$diffs;
}
if (($extra != null) && ($row->Extra != $extra)) {
++$diffs;
}
if ($diffs > 0) {
return false;
}
return true;
} // end if found our column
}
return false;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/check_column/