Mega Class Database (MYSQL) v 1.0 Use every feature of MySQL in PHP . Main Features: 1. MySQL Compatible with:MySQL 3.23+, MySQL 4.0+, MySQL 4.1+, MySQL 5.0+. 2. Easy to Use, clean, easy to understand code. 3. Access MySQL Database without any knowledge of MySQL or SQL . 4. Uses Associative array of data to insert and update rows in the database table. 5. Optional escape string feature to avoid SQL Injections. 6. Automatically Creates Prepared Statements. 7. Select Rows, Columns, Variables with one-liners. 8. Easy Select, Insert, Update, Delete, filtered 9. Properly documented with examples and comments. 10. Small Size. 11. Attach Fully Documented. Functions
// Connect to server sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false); //-----------------------------------------------------------------+ sql_query($query = ''); // Build sql statement from array for select and select distinct statements //-----------------------------------------------------------------+ // Build LIMIT query sql_query_limit($query, $total, $offset = 0); //-----------------------------------------------------------------+ // Fetch current row sql_fetchrow($query_id); //-----------------------------------------------------------------+ //Possible query values: SELECT, SELECT_DISTINCT function sql_build_query($query, $array); //-----------------------------------------------------------------+ // Run more than one insert statement. sql_multi_insert($table, &$sql_ary); //-----------------------------------------------------------------+ // Escape string used in sql query sql_escape(); //-----------------------------------------------------------------+ // Gets some information about the specified table. get_table_status($table_name); //-----------------------------------------------------------------+ // Gets the exact number of rows in a specified table. get_row_count($table_name); //-----------------------------------------------------------------+ //Gets the estimated number of rows in a specified table. get_estimated_row_count($table_name); //-----------------------------------------------------------------+ // display sql error page sql_error(); //-----------------------------------------------------------------+ // Build IN or NOT IN sql comparison string, uses <> or = on single element sql_in_set($field, $array, $negate = false, $allow_empty_set = false); //-----------------------------------------------------------------+ // Correctly adjust LIKE expression for special characters sql_like_expression($expression); //-----------------------------------------------------------------+ // Version information about used database sql_server_info(); //-----------------------------------------------------------------+ // Return number of affected rows sql_affectedrows(); //-----------------------------------------------------------------+ // Seek to given row number sql_rowseek($rownum, &$query_id); //-----------------------------------------------------------------+ // Get last inserted id after insert statement sql_nextid(); //-----------------------------------------------------------------+ // Free sql result sql_freeresult($query_id = false); //-----------------------------------------------------------------+ // close sql connection sql_close(); //-----------------------------------------------------------------+
Usage
// define class file in your script. define('IN_MEGA_DB', true);
// Include class file in your script. include('mega.class.database.php');
$dbhost = 'localhost'; $dbport = ''; $dbname = 'database'; $dbuser = 'db_username'; $dbpasswd = 'db_password'; $tableprefix = '';
//ex table used @define('USERS_TABLE', $tableprefix . 'users');
//New Class $db = new dbal_mysql();
// connect Database $con = sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
//-----------------------------------------------------------------+ // SELECT, INSERT, UPDATE, DELETE with prepared statements: //-----------------------------------------------------------------+ // SELECT $sql = $db->sql_query("SELECT * FROM ".USERS_TABLE.""); $row = $db->sql_fetchrow($sql); // OR while while($row = $db->sql_fetchrow($sql)) { // While code } //-----------------------------------------------------------------+ // INSERT $sql_ins = array( 'id' => (int)'', 'username' => 'username', 'password' => '123456', 'email' => 'email@email.com', 'status' => (int)'1', ); $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ins); $result = $db->sql_query($sql); //-----------------------------------------------------------------+ // UPDATE $db->sql_query("UPDATE " . USERS_TABLE . " SET `password`='123456' WHERE `id` = '1'"); //-----------------------------------------------------------------+ // DELETE $db->sql_query("DELETE " . USERS_TABLE . " WHERE `id` = '1'"); //-----------------------------------------------------------------+ // LIMIT QUERY if(!isset($_GET['page'])){$page = 1;}else{$page = intval($_GET['page']);} $sql_limit = '10'; $sql_start = ( $sql_limit * $page ) - $sql_limit; $sql = "SELECT * FROM ".USERS_TABLE." ORDER BY date DESC"; $result = $db->sql_query_limit($sql,$sql_limit, $sql_start); while ($row = $db->sql_fetchrow($result)) { // While code } //-----------------------------------------------------------------+ // Num Rows echo $db->get_row_count(USERS_TABLE); echo $db->get_estimated_row_count(USERS_TABLE);
Version History
v1.0 Initial version.