gpt4 book ai didi

php - SHOW FIELDS FROM mysql 表没有结果

转载 作者:行者123 更新时间:2023-11-29 00:41:48 25 4
gpt4 key购买 nike

我正在做一个后台项目——我首先实现了添加、更新和删除数据库条目,现在我需要对某些数据类型执行一些特定的操作。所以我想检索数据类型只有 $fieldtypes = mysql_query("SHOW FIELDS FROM mysqltable");返回 NULL

此时代码是这样的:

<?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)

谁能帮我找出问题所在?

谢谢!

最佳答案

即使使用像 SHOW FIELDS 这样的元数据查询,您仍然需要从结果资源中获取行。它的行为类似于返回行的常规查询,因此可以像往常一样在 while 循环中获取它们。

$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();

顺便说一句,当变量没有被插入到字符串中时,用双引号将变量括起来是不必要和多余的:

// Don't quote these vars -- it's poor practice
$connexion = mysql_connect("$serveur","$user","$password")

关于php - SHOW FIELDS FROM mysql 表没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963034/

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