0

I have an query like

SELECT EmployeeName FROM Employee

Query result will be :

Mr. Kamal
Mr. Karim
Mr. Rahim
Mr. Jamal

But I need :

Mr. Kamal , Mr. Karim, Mr. Rahim, Mr. Jamal

Is it possible with a single query.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mohammed Faruk
  • 495
  • 1
  • 9
  • 20
  • 2
    Possible duplication of http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string – hkutluay Jun 14 '12 at 05:41
  • 1
    Once you get the results using a query you can process it and do what ever you want in code. simple you can convert the result to an array in this specific case, isn't it? – Shiham Jun 14 '12 at 05:45

1 Answers1

0

You can do something like this :

# DATA SOURCE NAME
$dsn = "dbi:mysql:$database:localhost:3306";

# PERL DBI CONNECT
$connect = DBI->connect($dsn, $user, $pw);

# PREPARE THE QUERY
$query = "SELECT EmployeeName FROM  Employee ORDER BY id";
$query_handle = $connect->prepare($query);

# EXECUTE THE QUERY
$query_handle->execute();

# BIND TABLE COLUMNS TO VARIABLES
 $query_handle->bind_columns(undef, \$id);

 # LOOP THROUGH RESULTS
 while($query_handle->fetch()) {
   print "$employeeName" ,;
} 
vijay
  • 2,034
  • 3
  • 19
  • 38