PHP Classes

Convert MySQL tables to PHP class: Generate code to access MySQL records as objects

Recommend this page to a friend!
  Info   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (10)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 62%Total: 3,758 This week: 1All time: 873 This week: 560Up
Version License PHP version Categories
mysql_ 1.2GNU Lesser Genera...5PHP 5, Databases, Code Generation
Description 

Author

This class can be used to generate code to access MySQL records as objects.

It accesses a given MySQL database and retrieves the list of tables and information about the respective table fields.

The class can generate code for classes that can be used to access the respective MySQL table records as if they were objects.

The generated classes can have getter and setter functions for each table field, functions to insert or update records with the object values, functions to load a record with a given identifier, and delete the object record.

Picture of Rafael Rocha
Name: Rafael Rocha <contact>
Classes: 1 package by
Country: Portugal Portugal
Age: 37
All time rank: 85111 in Portugal Portugal
Week rank: 411 Up3 in Portugal Portugal Up

Details

/* * Author: Rafael Rocha - www.rafaelrocha.net - http://projects.rafaelrocha.net/ - info@rafaelrocha.net or rafael_xl1@hotmail.com for any question - EN and PT * * Date: 26.04.2009 * * Version: 1.1 * * License: LGPL * * What do: This is a class to convert your mysql * tables into php classes. * */ Indice I-What do? II - Install III - How to use functions IV - About author V - Bugs Fixed and Other important things I - What this class do?*************************** Run index.php, set the mysql connection settings. This will be convert all your tables into php classes. For exemple you have table: Users, Products. You will have users.class.php and products.class.php. With getters and setters and other nice functions. Any question info@rafaelrocha.net. II - Install *************************** Just run index.php and put in the Textfields mysql information. Make sure that file directory is 777CHMOD. III - How to use functions *************************** After you have all of your classes put them into library folder FOR EXAMPLE: (just a example) library/users.class.php products.class.php public_html/index.php in public_html/index.php use: require '../users.class.php'; require '../products.class.php'; Now you can use! $Classe_user = new users(); // use to connect to mysqli with class DataBaseMysql.class.php //Load user id=4 ******* $Classe_user->Load_from_key(4); //OK! now you can use that by getfunction. You can have all information in ROW id=4! echo $Classe_user->getName(); echo $Classe_user->getPassword(); //Construct******* $Classe_user->New_user("Rafael", "pasword"); //you had clear by reload new information into variable $Classe_user->Save_Active_Row_as_New(); // save this new user as a new in table //Set Function ANd Save_active_row() ******* $Classe_user->Load_from_key(4); //all information about id=4 $Classe_user->setName = ("John"); // Rafael -> John (same password yet!) $Classe_user->Save_Active_Row(); // UPDATE row in table //Delete_row_from_key($key_row){} ******* $Classe_user->Delete_row_from_key(4); //delete row that have id=4. //GetKeysOrderBy($column, $order) ******* $keys = $Classe_user->GetKeysOrderBy("name", "desc"); // array of keys order by name desc. You can put asc for($i=0; $i!=sizeof($keys); $i++){ run all the array $Classe_user->Load_from_key($keys[$i]); // possicion in key array, to load information echo $Classe_user->name; //right information, with orther by name desc. } //you see that just a simple for and array off keys, you can have all users information simplY!!! IV - About Author ********************** Rafael Rocha is from Póvoa de Santo Adrião > Odivelas > Lisboa > Portugal Study in ISCTE LISBON engº informatica info@rafaelrocha.net or rafael_xl1@hotmail.com for any question - EN and PT www.rafaelrocha.net http://projects.rafaelrocha.net/ -> to libraries V - Bugs fixed and other important things * Bugs fixed in 1.1: * 1º Mysqli query function * 2º Save as new function on classes * Bugs still hapen: * 1º table keys in end of table missing. So don´t let your table keys in end of table fields IMPORTANT: This classe use mysqli classe, that just php 5.0 have! if you don´t have mysqli function, you need to install manual.

  Files folder image Files  
File Role Description
Files folder imagedemo (4 files)
Accessible without login Plain text file Index.php Example Index to run
Plain text file SQL_to_PHP.class.php Class SQL to PHP class
Accessible without login Plain text file ReadmeEN.txt Doc. Documentation

  Files folder image Files  /  demo  
File Role Description
  Plain text file DataBaseMysql.class.php Class Data Base Connection Class
  HTML file index.php Class Main page
  Accessible without login Plain text file Readmefirst.txt Conf. Read me file
  Plain text file users.class.php Class user class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:3,758
This week:1
All time:873
This week:560Up
User Ratings User Comments (5)
 All time
Utility:79%StarStarStarStar
Consistency:85%StarStarStarStarStar
Documentation:68%StarStarStarStar
Examples:77%StarStarStarStar
Tests:-
Videos:-
Overall:62%StarStarStarStar
Rank:883
 
Class is helpful.
10 years ago (somnath shinde)
70%StarStarStarStar
Excellent work.
14 years ago (Todd J. Mullen)
77%StarStarStarStar
- some naming errors - insecure
14 years ago (Tom Schaefer)
20%StarStar
Very nice php-class! Very useful to access different types of...
14 years ago (Niemand)
80%StarStarStarStarStar
Very Good!
14 years ago (wanderley albuquerque)
77%StarStarStarStar