Posted By

yeremiloli on 08/13/10


Tagged

mysql php server connect localhost


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ltimsi
shawntysco


Simple Class Connection


 / Published in: PHP
 

  1. <php
  2. /**
  3. * Simple Class Connect
  4. */
  5.  
  6. class Connect {
  7.  
  8. var $host="localhost";
  9. var $dbname="yourdatabase";
  10. var $usuario="userserver";
  11. var $password="passwordserver";
  12. var $link;
  13. var $unlink;
  14.  
  15. function onServer()
  16. {
  17. $this->link = mysql_connect($this->host, $this->usuario, $this->password);
  18. $this->database = mysql_select_db($this->dbname);
  19. }
  20.  
  21.  
  22. function offServer()
  23. {
  24. $this->unlink = mysql_close($this->link);
  25. }
  26.  
  27. }
  28.  
  29. $var = new Connect();
  30. $var->onServer();
  31. echo 'run your queries here';
  32. $var->offServer();
  33. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: james0rion on August 14, 2010

If you are doing something this simple, why not just change onServer() to __construct() and offServer to __destruct(). That way all you have to do is: $var = new Connect; //queries here unset($var);

You need to login to post a comment.