doushu7588 2012-08-15 01:36
浏览 255
已采纳

在SHOW FIELDS FROM mysql表中没有结果

I'm working on a back office project - I first implemented add, update and delete database entries and now I need to imlement some specific actions on some datatypes. So I want to retrieve the datatype Only the $fieldtypes = mysql_query("SHOW FIELDS FROM mysqltable"); returns NULL

This is how code is at this time :

<?php
$serveur='localhost'; 
$user='root'; 
$password='xxxx'; 
$base='db'; 
$champs=array(
"member"=>array("id","group","login","lastname","firstname","email","pswd","account","searchingfor","searchingfordistance","searchedfor","searchedfordistance","mydescription","groupdescription","searchdescription","resourcesdescription"),
    "place"=>array("id","idm","ids","name","town","postalcode","address","coord")
);

$connexion = mysql_connect("$serveur","$user","$password") or die ("Impossible de se connecter à la base de données");
mysql_select_db("$base",$connexion) or die("Erreur de connexion a la base de donnees");

$fieldtypes = mysql_query("SHOW FIELDS FROM place");

ob_start(); 
var_export($fieldtypes); 
$tab_debug=ob_get_contents(); 
ob_end_clean(); 
$fichier=fopen('gs.log','w'); 
fwrite($fichier,$tab_debug); 
fclose($fichier); 

... (rest of code works)

Can anyone help me to find out what went wrong ?

Thanks!

  • 写回答

1条回答 默认 最新

  • dsifjgogw48491752 2012-08-15 01:39
    关注

    Even with a metadata query like SHOW FIELDS, you still need to fetch rows from your result resource. It behaves like a regular query returning rows, so fetch them in a while loop like you always would.

    $fields = array();
    $fieldtypes = mysql_query("SHOW FIELDS FROM place");
    if ($fieldtypes) {
      while ($row = mysql_fetch_assoc($fieldtypes)) {
        $fields[] = $row;
      }
    }
    ob_start(); 
    // Dump your $fields array
    var_export($fields); 
    $tab_debug=ob_get_contents(); 
    ob_end_clean(); 
    

    By the way, it is unnecessary and redundant to surround variables in double quotes when they are not being interpolated inside a string:

    // Don't quote these vars -- it's poor practice
    $connexion = mysql_connect("$serveur","$user","$password")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退