These functions are intended to create automatically php classes from MySQL tables.
- Fill SQL database information in
getDatabase
function ofutils.php
file. - Access to
phpSqlToClass.php
- Enter desired database and table
- Choose if you prefer the output on browser or on file
- Click on
Generate
- Auto indent file with you IDE
Extracted from example directory.
if(My_class::create("myId", "Test 1", date("Y-m-d"), time(), 0)){
echo "The object is created in database!";
}
else{
echo "Error while creating new object";
}
$id = "myId";
$myObject = My_class::wrapper($id);
if(!is_null($myObject)){
echo "The object is:<br>" . $myObject;
}
else{
echo "The object with id $id doesn't exist in database!<br>";
}
$id = "myId";
$myObject = My_class::wrapper($id);
if(!is_null($myObject) && $myObject->delete()){
echo "Object successfully deleted!<br>";
}
else{
echo "Error while deleting the object.<br>";
}
$id = "myId";
$myObject = My_class::wrapper($id);
if(!is_null($myObject) && $myObject->update("New name", "2021-09-12", "2021-09-12 08:04:30", 0)){
echo "Object successfully updated!<br>";
}
else{
echo "Error while updating the object. Maybe setted values are the same as before.<br>";
}
$id = "myId";
$myObject = My_class::wrapper($id);
if(!is_null($myObject)){
echo "The name of the object is {$myObject->getName()}.<br>";
}
else {
echo "The object with id $id doesn't exist in database!<br>";
}
$id = "myId";
$myObject = My_class::wrapper($id);
if(!is_null($myObject) && $myObject->setName("New name")){
echo "The new name of the object is {$myObject->getName()}.<br>";
}
else {
echo "The new name hasn't been changed.<br>";
}