TitanicLinux.Net :: Create (insert) and Save (update) PHP examples



Create (insert) and Save (update) PHP examples

Posted by anonymous 20.07.2004 00:46

Some PHP code examples to Create and Save a record would be useful.

Thanks for the great tool.


Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 21.07.2004 22:36

This is just a quick follow-up to my previous message.

Using the column names found in DaoGen's loadall() example, here's how to create (insert) and save (update) a record with PHP.

With data POSTed from a form, set the property values then use the "create" method:

$Customer = new Customer();

$Customer->setCreated($_POST['Created']);
$Customer->setCompanyName($_POST['CompanyName']);
$Customer->setNumber($_POST['Number']);
$Customer->setAddress($_POST['Address']);
$Customer->setBalance($_POST['Balance']);

$customerHandler->create($connection, $Customer);


To update a record, set the ID property value then use the "save" method.

$Customer = new Customer();

$Customer->setID($_POST['ID']);
$Customer->setCreated($_POST['Created']);
$Customer->setCompanyName($_POST['CompanyName']);
$Customer->setNumber($_POST['Number']);
$Customer->setAddress($_POST['Address']);
$Customer->setBalance($_POST['Balance']);

$customerHandler->save($connection, $Customer);


This might be obvious to many, but maybe it'll save others some time.


Re: Create (insert) and Save (update) PHP examples

Posted by Luigi 23.07.2004 16:28

> anonymous 20.07.2004 00:46
> Some PHP code examples to Create and Save a record would be useful.

You are right about examples. I am planning to write more examples, but somehow something else seems allways more important/interesting to do. My programming efforts are mostly targeted to enhance FastCMS and it still has quite a lot to do. However, I promise that I will try to find some time for the examples.

> Thanks for the great tool.

Thanks for good feedback, I hope you will find DaoGen useful!

// Luigi


CRUD Application Generation

Posted by anonymous 16.07.2005 06:10

If CRUD application can also be generated,
That's great!


Re: CRUD Application Generation

Posted by Luigi 07.08.2005 14:18

I am sorry, but I have no idea of what is GRUD application.

// Luigi


Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 08.09.2005 12:15

> anonymous 21.07.2004 22:36
> [...]
>
> $Customer->setNumber($_POST['Number']);
> [...]
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->create($connection, $Customer);
>
>
> To update a record, set the ID property value then use the "save" method.
>
> $Customer = new Customer();
>
> $Customer->setID($_POST['ID']);
> $Customer->setCreated($_POST['Created']);
> $Customer->setCompanyName($_POST['CompanyName']);
> [...]
> $Customer->setAddress($_POST['Address']);
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->save($connection, $Customer);

Relating to the above:

How does DaoGen generated code behave in reference to NULL fields?

Does it retrieve and store them correctly?

Or does it transform NULL to '' (<--- empty string)?


Re: Re: Re: Create (insert) and Save (update) PHP examples

Posted by Luigi 14.09.2005 12:29

Hello,

NULL values are no problem when you use object types when defining the database structure. Strings are allways objects and they behave always correctly with NULL values but for numeric types you must use spesific object versions for these types. The general idea with object types is that NULL values are preserved. With primitive types (the opposite of object type) NULL values are converted to 0.

// Luigi


Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:30

> anonymous 21.07.2004 22:36
> This is just a quick follow-up to my previous message.
>
> Using the column names found in DaoGen's loadall() example, here's how to create (insert) and save (update) a record with PHP.
>
> With data POSTed from a form, set the property values then use the "create" method:
>
> $Customer = new Customer();
>
> $Customer->setCreated($_POST['Created']);
> $Customer->setCompanyName($_POST['CompanyName']);
> $Customer->setNumber($_POST['Number']);
> $Customer->setAddress($_POST['Address']);
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->create($connection, $Customer);
>
>
> To update a record, set the ID property value then use the "save" method.
>
> $Customer = new Customer();
>
> $Customer->setID($_POST['ID']);
> $Customer->setCreated($_POST['Created']);
> $Customer->setCompanyName($_POST['CompanyName']);
> $Customer->setNumber($_POST['Number']);
> $Customer->setAddress($_POST['Address']);
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->save($connection, $Customer);
>
>
> This might be obvious to many, but maybe it'll save others some time.


Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:30




Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:36

> anonymous 20.07.2004 00:46
> Some PHP code examples to Create and Save a record would be useful.
>
> Thanks for the great tool.


Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:36

> anonymous 21.07.2004 22:36
> This is just a quick follow-up to my previous message.
>
> Using the column names found in DaoGen's loadall() example, here's how to create (insert) and save (update) a record with PHP.
>
> With data POSTed from a form, set the property values then use the "create" method:
>
> $Customer = new Customer();
>
> $Customer->setCreated($_POST['Created']);
> $Customer->setCompanyName($_POST['CompanyName']);
> $Customer->setNumber($_POST['Number']);
> $Customer->setAddress($_POST['Address']);
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->create($connection, $Customer);
>
>
> To update a record, set the ID property value then use the "save" method.
>
> $Customer = new Customer();
>
> $Customer->setID($_POST['ID']);
> $Customer->setCreated($_POST['Created']);
> $Customer->setCompanyName($_POST['CompanyName']);
> $Customer->setNumber($_POST['Number']);
> $Customer->setAddress($_POST['Address']);
> $Customer->setBalance($_POST['Balance']);
>
> $customerHandler->save($connection, $Customer);
>
>
> This might be obvious to many, but maybe it'll save others some time.


Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:37

> Luigi 23.07.2004 16:28
> > anonymous 20.07.2004 00:46
> > Some PHP code examples to Create and Save a record would be useful.
>
> You are right about examples. I am planning to write more examples, but somehow something else seems allways more important/interesting to do. My programming efforts are mostly targeted to enhance FastCMS and it still has quite a lot to do. However, I promise that I will try to find some time for the examples.
>
> > Thanks for the great tool.
>
> Thanks for good feedback, I hope you will find DaoGen useful!
>
> // Luigi


Re: CRUD Application Generation

Posted by anonymous 29.05.2006 04:37

> anonymous 16.07.2005 06:10
> If CRUD application can also be generated,
> That's great!


Re: Re: Re: Create (insert) and Save (update) PHP examples

Posted by anonymous 29.05.2006 04:37

> anonymous 08.09.2005 12:15
> > anonymous 21.07.2004 22:36
> > [...]
> >
> > $Customer->setNumber($_POST['Number']);
> > [...]
> > $Customer->setBalance($_POST['Balance']);
> >
> > $customerHandler->create($connection, $Customer);
> >
> >
> > To update a record, set the ID property value then use the "save" method.
> >
> > $Customer = new Customer();
> >
> > $Customer->setID($_POST['ID']);
> > $Customer->setCreated($_POST['Created']);
> > $Customer->setCompanyName($_POST['CompanyName']);
> > [...]
> > $Customer->setAddress($_POST['Address']);
> > $Customer->setBalance($_POST['Balance']);
> >
> > $customerHandler->save($connection, $Customer);
>
> Relating to the above:
>
> How does DaoGen generated code behave in reference to NULL fields?
>
> Does it retrieve and store them correctly?
>
> Or does it transform NULL to '' (<--- empty string)?



viimeisin päivitys: 30.06.2009 16:49 Author: TitanicLinux.Net
Copyright TitanicLinux.Net 2003-2010