database wrapper

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

database wrapper

Post by shivam0101 »

when writing query for select statement,

Code: Select all

function Select($tablename)
{
  $query='SELECT * FROM tablename';
  while($fetch=mysql_fetch_array($query))
  {
   $fetched_arr=$fetch;
  }
}

usage:

Code: Select all

$data=Select('table')
if the number of record is 1 i have to use $data[0], if its more than 1 record, i have to use $data to display results. How to write a better query so it can be handled in same way on both occassions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your function returns nothing. $data[0] will create an error.
Post Reply