Jump to content

Recommended Posts

HI!

 

I'm looking for an application/script that generates PHP code automatically. I want to create classes just for manipulating a MySQL database, i dont need the HTML, i just need the PHP classes for manipulating the database.

 

Class example:

 

require database.php

 

class tableclients {

 

//fields

 

function insert(...) {}

function delete(...) {}

function update(...) {}

function select(...) {}

.

.

.

 

}

 

I have a database with too many tables and a script/application that can create all the classes with data validation is appreciated.

 

Does anyone knows a way to generate all of this code automatically.

 

Thanks  ;)

 

Sorry about my english.

Link to comment
https://forums.phpfreaks.com/topic/185549-php-mysql-oop-code-generator/
Share on other sites

I dont know why you would want something to do that for you when it is simple enough to do yourself. Not to mention the fact that you arent going to know if the validation is meeting what you need to validate. I do not know of any software out there that can do this and as far as I know there is no such thing. My suggestion is to write your own classes to manage your database.

I dont know why you would want something to do that for you when it is simple enough to do yourself. Not to mention the fact that you arent going to know if the validation is meeting what you need to validate. I do not know of any software out there that can do this and as far as I know there is no such thing. My suggestion is to write your own classes to manage your database.

 

I have so many tables. The validation that i'm talking is to validate fields, maxlength, datatype, nulls, and manipulating all errors of database consistency .

There are many database classes already made if thats what you are after. Just do a google search for a php database class. As far as a generator, I don't know if they exist, and a generator that just makes 1 class seems kind of pointless to make anyways.

ok so why dont you just create a class yourself? imagine if programmer out there just tried to have something done for them automatically. we would have NO good programmers. every programmer out there that i know has gone through some tedious work to validate fields. you could make a simple database class that you could pass values to to check.

 

<?php
class db{

function __construc(){
mysql_connect('host','user','pass');
mysql_select_db('db');
}

function validate($array){

switch($array[0]){
  case 'integer':
    if(is_numeric($array[1]))
       return true;
  case 'email':
   return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $array[1]);
}

}

}

//making use of the class
$db = new db();

//initialize a number
$number = 23;

//check that it is a number
$error = $db->validate(array('integer',$number));

//check the error
if($error == true){
  echo 'there was an error';
} else {
  echo 'your good to go';
}

 

 

See how easy that was and you could just extend that validate method or create one for each type of validation you needed. Then you could also create methods in that class for inserting and updating data.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.