Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***
- * Class: Sql
- * Version: 0.01
- *
- * Desc:
- * This is a simple class for managing mySQL connections.
- * I don't want this to do more then return the query though.
- * Formatting the query will be left to another class!
- *
- * The private connected bool is used for error checking in the class.
- */
- class Sql{
- private $Connected = false;
- /***
- * Protected function: isConnected
- * Version: 0.01
- *
- * Desc:
- * This simply returns the private Connected bools value.
- */
- protected function isConnected(){
- return $this->Connected;
- }
- /***
- * Function: doQuery
- * Version: 0.01
- *
- * Desc:
- * This function will return the data from the query,
- * if the constructor managed to set up a connection.
- * Otherwise it'll give out an error.
- */
- public function doQuery($queryString){
- if(!$this->isConnected()){
- return "ERROR no.1: Couldn't connect to DB.";
- }else{
- return "we got through!";
- }
- }
- /***
- * Function: __construct
- * Version: 0.01
- *
- * Desc:
- * This is the initializer of the class. It sets up some mySQL values
- * and then tries to establish a connection.
- * I should add error checking for the @mysql_connect and mysql_select_db.
- */
- function __construct(){
- $str_dbhost=""; //the database host name
- $str_dbuser=""; //the database user
- $str_dbname=""; //the database name
- $str_dbpass=""; //the database password
- $sqlconnection = @mysql_connect($str_dbhost,$str_dbuser,$str_dbpass);
- mysql_select_db($str_dbuser);
- if($sqlconnection){
- $this->Connected = true;
- }
- }
- function __destruct(){
- mysql_close();
- $this->Connected = false;
- echo "connection down.";
- }
- }
- $sql = new Sql();
- ?>
Add Comment
Please, Sign In to add comment