Delphi For PHP
Delphi For PHP
Delphi For PHP
We can use phpMyAdmin to create data-bases,tables inside the base and we can
add,change and delete subject within base.Simply,we will put in name of base which we
want to create in field named Create new database and we clik on button create and
automatically base will be created under the name you brought in.
Now,when we created data-base ,in easy way we can form table in that base in which
we will locate datas that we fill in.Simply,we will fill in the name of table we want to
make (in this case let it be datas for table name)and we will number of fields we will
use(I put 5for this our example-one for id,one for first name,one for last name,one for
addres and one for phone number suppose).
After filling in datas for name and number of table fields we will use,to differentiate
them we have to fill in their names too.We will fill in names and type for every field.In
this example I use only field for ID.It is integer type of bases (INT),because we will use
number in that field,and for others fields we will put VARCHAR,because we will use
some textual datas for values of those fields.
Also,you can define size of value that you fill in those fields and a lot of other presets,but
when it is primary tutorial,that part we will skip over because we dont need it right now.
Also,we can define what field will be the field of primary key;in our case we will
make that field as ID.When you have finished filling in names and adjusting in
conjuction with field type and defining of primary key,just click on save and inside
base with those field will be created table,where with you successfully finished the first
part of this small excample which followes.
Of course,you dont have to use php MyAdmin to create base and table inside that
base,you can make (program) in php also with this code:
PHP code for making the base: <?php /*
Justead user name a password,put your dates for connecting at your server.The most
often is mysql_connect (localhost,,);Or mysql_connect(localhost,root,);
When it is abou version of wamp that I recommended you,connecting with server you
can make if you put root as user name and you dont anything put as password,so
mysql_connect(localhost,root,);
$con=mysql_connect(localhost,root,);
mysql_query(CREATE DATABASE base directory);
echo The base is made
PHP code for making table: <?php
$con=mysql_connect(localhost,username,password);
If (!$con)
{
Die (It could not be connected on server!
Error: . mysql_error());
}
mysql_select_db(Base Directory,$con);
mysql_query(CREATE TABLE
datas (
id INT NOT NULL AUTO_INCREMENT
,PRIMARY KEY (id)
,name VARCHAR (30)
Address VARCHAR (50)
What we need is to register base that we will use,and we do that as we open helpful
PopUp menu with right click on item My SQL and we select option Register Databaseand after that we will get a window as on picture 7.In this part you chose tybe of
data-base we want to register on in this our case it is My SQL,name for connection that
will help you to conguer with larger number of bases that you can recognize them easier
and similar.Next we select type of host that we connect on,there we have to fill in
localhost,and D4PHP locate port on which server will watch your web application by
its own.
Data Explorerenable you to supervise tables and fields of data-base.By using
contexting menu you can sretae and guide with connections of data-bases.
Also,you can drag and drop(copy),information in majority forms to project more
applicatios with data-bases quickly.
After we filled in all demanded dates,with click on OK button in gaven
window,selected base will be registered for using.Altought the base is registered for
using.it isnt included in our application yet.The fastest and the easiest way t include it is
to drag and drop tables from registered base on form,and D4PHP will automaticly create
on form of component to connect them.(picture 8).
On the form now we will have four components,and one of them are not visual(Table,
Database and DataSource) components.DBGrid component servers as description of
datas of base,and the others serve to connect to base that we registered.
If we now turn on our application (picture 9),in web browes will be showed only
DBGrid component (picture 10).
Since our base is empty at the moment,we have to create a prt for inserting of datas in
it so our directory would have sence.Since we will fill in information about the first
name,last name,address,phone number of some person at our directory,we will add fields
for inserting those information.Find Edit and label components at the Tool Palletw and
set them up on defined parts of form.We need four Edit components and label
components we will set up to give us direction which Edit component is acts for ad we
will need one Button component which will activate code for inserting of those
datas.When you drag (and drop) that form of given component and dispose them as you
want to in ObjectInspector in Properties part,first we will change text of label component
to make easier later orientation.The text of label componentyou will change if you find
lot Caption in ObjectInspector Properties and give it a value of what you want to write in
given label components.I will pu shortly and clearingly in label components values The
first name,The last name,Address and Phone number.Button component,you will see,has
this same property which means that we can change its text to one we need;for our
example Iput Fill in datas!.
Also,every component has its Name property,id est name and through that
property youintermit it in the code.To make shift easily we will change names of Edit
components from Edit1,Edit2to
EditFirstName,EditLastName,EditAddress,EditPhone,and to Button component we will
attach name Button Fill in Datas!.
When we have finished designing we will start with programming of Button
component,id est we will add it a code with which it will fill in datas that we put in given
fields and locate them into the base and then those datas will be showed at DBGrid
component.
To program that button we will make a double click on Button component and
D4PHP will switch you to Code View and there we put code for inserting datas to base!
(picture 12)
D4PHP code for inserting datas to base:
Function Button Fill in Datas Click ($sender,$params)
{
$this ->tbdatas1->open();
$this->tbdatas!->firstname=$this->EditFirstName->Text
$this->tbdatas1->lastname=$this->EditLastName->Text
$this->tbdatas1->address=$this->EditAddress->Text
$this->tbdatas1->phone=$this->EditPhone->Text
$this->tbdatas1->post();
$this->tbdatas1->close():
$this->tbdatas1->Refresh().
}
Well,in this code we open table of datas that we registered and prepare it for
inserting of datas and then to every field of table we attach define value,id est text we fill
into Edit component,and after that we post text to base,we close it and refresh it so we
could see at DBGrid newmade datas.
After we turn on our application again and fill in a formulary whit information that
we set up for inserting and we click on button Fill in datas! at our browser,our directory
will be fed up with new information.(picture 13)
And with this we have finished part of this small introduction with developing
environment throw our example with directory.
Of course,it couldnt always be inserted correct information,often it could be made
some mistakes during the inserting,so we need to program a part that will be usefull for
modification of filled datas.
For modification in our base,we will program JavaSCript on event with double click
on DBGrid component.When we drag DBGrid component,on ObjectInspector JavaScript
coul be turned on,and since we want our to activate on double click inside the
DBGRid,we will select event OnDblClick (picture 14).
To program some event,id est to start programming some event,in the right corner of
the neme that presents on which event something will be activated,at empty space right
off that name at the same order you shouldmake double click and D4PHP will switch you
to code editor inside the function which automaticly is creating for given objects where
you can add your own code.(Picture 14)
JavaScript code for enabling modification of datas at the base:
Function dddatas1JSDblClick ($sender,$params)
{
?>
// Add your java script code here
Var temp =DBGrid1.getTableModel(/.get value(0,DBGrid1.getFocuseRowl());location
= unit2.php?id=+temp;return (false);
<?php
This part of code enable us to turn on our program and when we do double click
inside some field where information we filled in before are showed,to make us change
them like we fill in text we want to be showed in that field and then we just click on some
other field or press Enter on the keyboard and newfilled text will be remembered in our
base automaticly.
Of course,adding and changing of filled datas often isnt enough and there could be
need for deleting some datas from base.
For that we can use one another Edit and Button component on form and we will
give it name EditID because we will delete someone from our contact list like we write
its ID number to our EditID field and click on delete button,and that button program on
this way:
Code of button for deleting datas from base:
Function ButtonDeleteClick ($sender,$params)
{
$this->dbBaseDirectory1->execute (DELETE FROM datas WHERE id =. $this>EditID->Text.);
$this->tbdatas1->Refresh();
}
This code,as you can see.does SQL interrogation which says us to delete all datas
in order where field id is equally with value we fill in at EditID field on our form,and the
table datas refreshes so we can see made action.
And I congratulate,if you survived until here,your web application directory has
been made.
Everything that remains is to turn it on again and to play with it a little bit,freely
experiment a little,add some new options and similar.
Ready web application!(picture 15)
I hope that Ititillated your wish to introduce you with this program.
On large number of programmers forums can be notised that huge number of
Delphi programmers are excited with this tool,but also it could be found and those part of
PHP programmers who are not impressed with this way of programming,but anyway my
recommend is to try on this tool and to decide by yourself if it is adequate.
For couple of years,I have been working at Delphi and there I made desktop
applications,and recently I started with envirenments of web applications and I think that
I found the best tool for this.Since Delphi growed to my heart,sincerely,I couldnt
separate from IDE (..) and to resign to some of text editor,I decided to Delphi for PHP for
reason that I think that it is one of the tools which will very soon rise up between
environment tools of that species and grow them up in every view.
Of course,everybody couldnt agree with me about this,it is my opinion,and
everybody has right to different opinion,hasnt it?
Each goodness to all raeders of this tutorial.Vladica Simic [mail.]