PHP FUnction

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jackie111
Forum Newbie
Posts: 13
Joined: Thu Jun 23, 2005 3:16 am

PHP FUnction

Post by jackie111 »

i want to write my mysql connection code to a FUNCTIONS, when i need to open mysql connection, i just need to call it, how to write it? i am not familiar with php, thanks for all your help.
Jackie
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

You've come to the right place for help. But rather than hand feed it to you, I'll give you a short function sample that you can play with and learn from.

Code: Select all

function name($arg1,$arg2=TRUE){
   // do whatever you want in here
   mysql_connect("localhost",$arg1,$password)
      or die(mysql_error();
   // maybe echo something
   echo "connected";
   // you can return things in a function
   if($arg2)
      return 4+4;
}
play around with that some and do some tweaking and see what you come up with. If you need more help, you know where to find us :P
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

it seems the problem is solved :P so why dont you add a [SOLVED] tag to your subject :roll:
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Word of warning, the $password variable is just hanging out there, and you're going to have to define it yourself.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Ambush Commander wrote:Word of warning, the $password variable is just hanging out there, and you're going to have to define it yourself.
*heh guess that's what I get for trying to make someone think things through...was trying something new here

1) in response to dethron: this isn't [SOLVED]...I'd think far from it, it's a start to try and throw some bread crumbs out to make jackie work a little bit and learn in the process.

2) in response to AC (see *)

next time I guess I'll just go back to providing more thorough answers 8O
jackie111
Forum Newbie
Posts: 13
Joined: Thu Jun 23, 2005 3:16 am

Post by jackie111 »

thanks so much, i will check it right now.
Post Reply