for info for information_schema列数据类型不起作用

时间:2016-10-09 03:56:01

标签: php sql information-schema

我尝试了很多组合,但我似乎无法弄清楚为什么所有输入类型都会成为文本!

$columnquery = $conn->query("SELECT column_name, column_comment, data_type FROM information_schema.columns
    WHERE table_schema = '$dbname'
    AND table_name = '$tableName'");
if ($columnquery->num_rows > 0){

    while ($columnRows = $columnquery->fetch_assoc()) {
      $columnName = $columnRows["column_name"];
      $columnType = $columnRows["data_type"];

      if ($columnRows['column_comment'] != 'Pups' && $columnType = "varchar"){
      echo "$columnName: $columnType <input type='text' name='$columnName'><br>";
    }
    elseif ($columnRows['column_comment'] != 'Pups' && $columnType = "int") {
      echo "$columnName: $columnType <input type='number' name='$columnName'><br>";
    }
    elseif ($columnRows['column_comment'] != 'Pups' && $columnType = "date") {
      echo "$columnName: $columnType <input type='date' name='$columnName'><br>";
    }

}

1 个答案:

答案 0 :(得分:1)

单身&#34; =&#34;用于使变量等于某个东西以便比较你应该使用&#34; ==&#34;例如 $ columnquery = $ conn-&gt; query(&#34; SELECT column_name,column_comment,data_type FROM information_schema.columns     在哪里table_schema =&#39; $ dbname&#39;     AND table_name =&#39; $ tableName&#39;&#34;); if($ columnquery-&gt; num_rows&gt; 0){

while ($columnRows = $columnquery->fetch_assoc()) {
  $columnName = $columnRows["column_name"];
  $columnType = $columnRows["data_type"];

  if ($columnRows['column_comment'] != 'Pups' && $columnType == "varchar"){
  echo "$columnName: $columnType <input type='text' name='$columnName'><br>";
}
elseif ($columnRows['column_comment'] != 'Pups' && $columnType == "int") {
  echo "$columnName: $columnType <input type='number' name='$columnName'><br>";
}
elseif ($columnRows['column_comment'] != 'Pups' && $columnType == "date") {
  echo "$columnName: $columnType <input type='date' name='$columnName'><br>";
}

}