fantomel Posted April 4, 2009 Share Posted April 4, 2009 Hello i'm playing a little with php in this morning and i've started to build a wrapper for mysql.. an opinion advices, corrections would be nice and good <?php if (!defined('ANTIHACK')) { header('HTTP/1.0 403 Forbidden'); header('Status: 403 Forbidden'); die ("<br> You don't have access here."); } Class MySQL { var $dbConfigInfo; var $connect; var $row; public static function connect($dbConfigInfo = NULL) { static $connect; if (!is_array($dbConfigInfo) || count($dbConfigInfo) < 1) return FALSE; if (! isset ($connect)) { $connect = mysql_connect($dbConfigInfo['servername'], $dbConfigInfo['username'], $dbConfigInfo['password']); return $connect; } } public static function db($dbname) { $db = mysql_select_db($dbname) or die(mysql_error()); return $db; } public static function query($query) { return mysql_query($query, $connect); } public static function FetchArray($result = '') { return $row = mysql_fetch_array($result, MYSQL_BOTH); } } ?> And this is how it's used <?php $dbConfigInfo = array( 'servername' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'gallery', ); define('TBL_PRODUCTS', 'sometable'); define('TBL_CATEGORYS', 'sometable'); DEBUG ? error_reporting(E_ALL | E_STRICT) : error_reporting(0); if(!class_exists('MySQL')) include_once('classes/mysql.class.php'); $connect = MySQL::connect($dbConfigInfo); if(!$connect) die("Nu m-am putut conecta"); // TODO : Modificare erroare handler errori custom $db_select = MySQL::db($dbConfigInfo['dbname']); if(!$db_select) die("Nu am ptutu selecta."); // TODO : Modificare erroare handler errori custom ?> Link to comment https://forums.phpfreaks.com/topic/152519-oop-wrappers-mysql/ Share on other sites More sharing options...
redarrow Posted April 4, 2009 Share Posted April 4, 2009 use require_once. does the code work? Link to comment https://forums.phpfreaks.com/topic/152519-oop-wrappers-mysql/#findComment-801082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.