Jump to content


Photo

returning more then one thing in a function?


  • Please log in to reply
3 replies to this topic

#1 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 19 September 2006 - 09:49 PM

is it this correct?

<?php
function connect($localhost,$username,$password,$database);
mysql_connect('$localhost','$username','$password') or die(mysql_error));
mysql_select_db('$database') or die(mysql_error());
return $localhost,$username,$password,$database;
}
?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 September 2006 - 10:02 PM

No.

You can only return a single value, however that value can be an array. So you could

return array($localhost,$username,$password,$database);

But in that case, having passed those values to the function and they remain unchanges in the function, where's the point in then returning them again?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Demonic

Demonic
  • Members
  • PipPipPip
  • Advanced Member
  • 562 posts

Posted 19 September 2006 - 10:13 PM

so changing what i have to:
return array($localhost,$username,$password,$database);

would work?

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 September 2006 - 10:15 PM

Pointless, but should work.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users