Revision: 4172
Updated Code
at October 30, 2007 16:43 by wattz
Updated Code
<?php
require("myActiveRecord.php");
// this assumes that you have set your db authentication up in ActiveConnect.php
$activeRecord = new ActiveRecord('users'); //create a new object based on the table users
//
// Now we are going to create a new user:
//
// first we set values to all the fields in the Users table:
$activeRecord->username = "AppleSeed";
$activeRecord->firstname = "Johnny";
$activeRecord->lastname = "McIntosh";
$activeRecord->password = md5("myPassWord");
// Now we save the new record
$activeRecord->save();
// if the save was successful then it will not die and
// the id will be set to the last entry so you can
// reference it with: $activeRecord->id
// Lets say we made a mistake, we need the firstname to be
// John not Johnny, in this case we can update it using:
$activeRecord->firstname = "John";
// because $activeRecord->id was set to the id of the record we created,
// it will update that corresponding rows related to that id.
$activeRecord->save();
// now we want to update an older record, so we will need to find the user id
// with the username and password and then update based on the return id.
$userid = $activeRecord->getUseridWhere("username = 'wattz' AND password='passw0rd'");
// now we have the user's id, and we want to update the users email address and save the record:
$activeRecord->id = $userid;
$activeRecord->email = "[email protected]";
$activeRecord->save();
//...and thats it for that part
//
// Now we want to get all the users that have the db field "role" set to admin
// this is easy using myActiveRecord
// all we have to do is:
$adminUsers = $activeRecord->findByRole("admin");
// this will return all of the users in the db table with the Role "admin";
// to see the results simple do a var_dump or print_r.
// to delete a row, you simply use the delete command:
$activeRecord->deleteByEmail("[email protected]");
// myActiveRecord also includes simple static functions like:
$adminUsers = $activeRecord->findAll(); //returns all the records in a table
$adminUsers = $activeRecord->findAllWhere("role='admin"); //if you dont prefer the dynamic methods
// and if you have some strange query you need to run
// there is always the straight query command:
$adminUsers = $activeRecord->query("SELECT * FROM users WHERE role='admin'");
// and finally we have fieldCount, which simply gives you a total count of fields,
// with our without parameters
// total number of admin users
$adminUserCount = $activeRecord->fieldCount("role='admin'");
// total number of users.
$userCount = $activeRecord->fieldCount();
// There is much more about myActiveRecord that can be accomplished, visit www.wattz.net to download
// and utilize php and mysql with easy.
?>
Revision: 4171
Updated Code
at October 30, 2007 16:42 by wattz
Updated Code
<?php
require("myActiveRecord.php");
// this assumes that you have set your db authentication up in ActiveConnect.php
$activeRecord = new ActiveRecord('users'); //create a new object based on the table users
//
// Now we are going to create a new user:
//
// first we set values to all the fields in the Users table:
$activeRecord->username = "AppleSeed";
$activeRecord->firstname = "Johnny";
$activeRecord->lastname = "McIntosh";
$activeRecord->password = md5("myPassWord");
// Now we save the new record
$activeRecord->save();
// if the save was successful then it will not die and
// the id will be set to the last entry so you can
// reference it with: $activeRecord->id
// Lets say we made a mistake, we need the firstname to be
// John not Johnny, in this case we can update it using:
$activeRecord->firstname = "John";
// because $activeRecord->id was set to the id of the record we created,
// it will update that corresponding rows related to that id.
$activeRecord->save();
// now we want to update an older record, so we will need to find the user id
// with the username and password and then update based on the return id.
$userid = $activeRecord->getUseridWhere("username = 'wattz' AND password='passw0rd'");
// now we have the user's id, and we want to update the users email address and save the record:
$activeRecord->id = $userid;
$activeRecord->email = "[email protected]";
$activeRecord->save();
//...and thats it for that part
//
// Now we want to get all the users that have the db field "role" set to admin
// this is easy using myActiveRecord
// all we have to do is:
$adminUsers = $activeRecord->findByRole("admin");
// this will return all of the users in the db table with the Role "admin";
// to see the results simple do a var_dump or print_r.
// to delete a row, you simply use the delete command:
$activeRecord->deleteByEmail("[email protected]");
// myActiveRecord also includes simple static functions like:
$adminUsers = $activeRecord->findAll(); //returns all the records in a table
$adminUsers = $activeRecord->findAllWhere("role='admin"); //if you dont prefer the dynamic methods
// and if you have some strange query you need to run
// there is always the straight query command:
$adminUsers = $activeRecord->query("SELECT * FROM users WHERE role='admin');
// and finally we have fieldCount, which simply gives you a total count of fields,
// with our without parameters
// total number of admin users
$adminUserCount = $activeRecord->fieldCount("role='admin'");
// total number of users.
$userCount = $activeRecord->fieldCount();
// There is much more about myActiveRecord that can be accomplished, visit www.wattz.net to download
// and utilize php and mysql with easy.
?>
Revision: 4170
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 30, 2007 16:41 by wattz
Initial Code
<?php
require("myActiveRecord.php");
// this assumes that you have set your db authentication up in ActiveConnect.php
$activeRecord = new ActiveRecord('users'); //create a new object based on the table users
//
// Now we are going to create a new user:
//
// first we set values to all the fields in the Users table:
$activeRecord->username = "AppleSeed";
$activeRecord->firstname = "Johnny";
$activeRecord->lastname = "McIntosh";
$activeRecord->password = md5("myPassWord");
// Now we save the new record
$activeRecord->save();
// if the save was successful then it will not die and
// the id will be set to the last entry so you can
// reference it with: $activeRecord->id
// Lets say we made a mistake, we need the firstname to be
// John not Johnny, in this case we can update it using:
$activeRecord->firstname = "John";
// because $activeRecord->id was set to the id of the record we created,
// it will update that corresponding rows related to that id.
$activeRecord->save();
// now we want to update an older record, so we will need to find the user id
// with the username and password and then update based on the return id.
$userid = $activeRecord->getUseridWhere("username = 'wattz' AND password='passw0rd');
// now we have the user's id, and we want to update the users email address and save the record:
$activeRecord->id = $userid;
$activeRecord->email = "[email protected]";
$activeRecord->save();
//...and thats it for that part
//
// Now we want to get all the users that have the db field "role" set to admin
// this is easy using myActiveRecord
// all we have to do is:
$adminUsers = $activeRecord->findByRole("admin");
// this will return all of the users in the db table with the Role "admin";
// to see the results simple do a var_dump or print_r.
// to delete a row, you simply use the delete command:
$activeRecord->deleteByEmail("[email protected]");
// myActiveRecord also includes simple static functions like:
$adminUsers = $activeRecord->findAll(); //returns all the records in a table
$adminUsers = $activeRecord->findAllWhere("role='admin"); //if you dont prefer the dynamic methods
// and if you have some strange query you need to run
// there is always the straight query command:
$adminUsers = $activeRecord->query("SELECT * FROM users WHERE role='admin');
// and finally we have fieldCount, which simply gives you a total count of fields,
// with our without parameters
// total number of admin users
$adminUserCount = $activeRecord->fieldCount("role='admin'");
// total number of users.
$userCount = $activeRecord->fieldCount();
// There is much more about myActiveRecord that can be accomplished, visit www.wattz.net to download
// and utilize php and mysql with easy.
?>
Initial URL
www.wattz.net
Initial Description
MyActiveRecord is a stand alone db abstraction layer to simplify things between php and mysql. you can download the latest version from www.wattz.net
Initial Title
Using PHP and MyActiveRecord ( from www.wattz.net)
Initial Tags
mysql, php
Initial Language
PHP