Search code examples
phprecordset

Recordet.update in PHP


I am developing an application in PHP. I m basically a ASP programmer. In ASP we update a record using recordset.update command. Is this possible in PHP.

my requirement is to update individual field of a record not all the fields in one statement.

Example in ASP with SQLserver as database

set rs=server.createobject("adodb.recordset")

loop through individual fields of the records or table
for i=0 to fields.count-1
{
       get data for each field from web form
       rs(i)=fields.name
       rs.update 
}

is the above code is possible in PHP using MYSQL.


Solution

  • Are you using core PHP or any framework? if you are using core PHP then the answer is that, in foreach loop you will be updating the each record manually. i.e. the fields you have made changes in, you will update them via update query as you will have the Primary key of that record in foreach loop, also you will the having column names.

    And if you are using any framework like YII then you just have to change the attribute values you made changes in, and call the update function like $model->update(); as you are doingin your ASP code.