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!
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 awhileloop like you always would.By the way, it is unnecessary and redundant to surround variables in double quotes when they are not being interpolated inside a string: