5

I'm using CodeIgniter 2.1.3. I have problem with function list_fields() which should return an array of fields of the MySQL result. So my code below should list all fields of the MySQL result.

$query = $this->db->query("SELECT * from $tablename where REGNO='$keyword' " );
$fields  = $query->list_fields();
foreach ($fields as $f)
{
echo $f;
} 

It works fine in Windows but it is not working in Linux, but if the number of rows are zero in results, it works even in Linux.

Any idea what's going wrong?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Sagar
  • 980
  • 1
  • 11
  • 27
  • Your code is sound, which can only mean your sql is wrong, or it isn't returning any results. I suggest showing the entire function. – Jeemusu Dec 03 '12 at 03:41
  • my query is $query = $this->db->query("SELECT * from $tablename where REGNO='$keyword' " ); Not that I added query line to the code. – Sagar Dec 03 '12 at 04:57
  • I assume you're escaping your `$keyword`. if you did no need for '' in the query as the escape method in CI does it for you. might be your problem – eric.itzhak Dec 03 '12 at 05:14
  • but $query->result() works fine. and also – Sagar Dec 03 '12 at 05:21
  • it looks like you're trying to get the fields from your result. you might need to drill down to the row() level before you try to access that information – b_dubb Mar 04 '13 at 04:07

1 Answers1

0

Try to check if there are any errors of your mysql on your linux machine (usually located in /var/log/mysql/error.log).

Make sure that the PHP and MySQL version in your Linux machine is the same as your Windows machine in case there are bugs on them in particular version.

SubRed
  • 3,169
  • 1
  • 18
  • 17
  • php is not showing errors in my Linux version. I changed the php.ini file but doesn't effected. but later I came to know that there are two copies of that file and I edited them both as display_errors = on, then it showed some errors. I fixed them. now the code was perfect but I cant understand that why the same code with errors in Linux worked in windows ? – Sagar Dec 03 '12 at 14:05
  • @Sagar sory for late reply. Well different environment can output different result for example on windows you can read table with case insensitive while in linux you can't. There are also known bugs on some version of PHP handle particular version of MySQL. – SubRed Dec 04 '12 at 00:48