2012-08-15 3 views
1

저는 백 오피스 프로젝트에서 작업하고 있습니다 - 먼저 데이터베이스 항목을 추가, 업데이트 및 삭제하고 일부 데이터 유형에 대한 특정 작업을 구현해야합니다. 그래서 데이터 유형 만 검색하고 싶습니다. $ fieldtypes = mysql_query ("SHOW FIELDS FROM mysqltable");mysqltable에서 SHOW FIELDS에 대한 결과가 없습니다.

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

사람이 무엇이 잘못되었는지 알아 좀 도와 줄래 : 리턴이 코드는이 시간에 얼마나입니다

NULL?

감사합니다.

답변

1

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") 
+0

이 아, 네 대단히 감사합니다 :) –

관련 문제