Titre du sujet : Re: classGenerator -> méthode insert ne fonctionne pas par DaBoyz sur 03/08/2005 23:45:32
Je ne voulais pas le faire de suite vu la taille (je met tout comme ça, c'est fait) :
include_once XOOPS_ROOT_PATH.'/class/xoopsobject.php';
/**
* dbv_persons Class
*
* This class is responsible for providing data access mechanisms to the data source of Xoops dbv_persons class objects.
*
* @author Vincent Fourastié
* @package DB Volley
* @version 1.0
*/
class dbv_persons extends XoopsObject
{
function dbv_persons( $id = null )
{
$this->db =& Database::getInstance();
$this->initVar( 'persons_id', XOBJ_DTYPE_INT, null, false, 10 );
$this->initVar( 'persons_sex', XOBJ_DTYPE_INT, null, false, 10 );
$this->initVar( 'persons_surname', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_firstname', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_nicknames', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_country', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_country2', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_birth', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_height', XOBJ_DTYPE_INT,null, false, 10 );
$this->initVar( 'persons_birthwhere', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_picture', XOBJ_DTYPE_TXTBOX, null, false );
$this->initVar( 'persons_xoopsid', XOBJ_DTYPE_INT, null, false, 10 );
$this->initVar( 'persons_occupation', XOBJ_DTYPE_INT, null, false, 10 );
$this->initVar( 'persons_lastupdate', XOBJ_DTYPE_TXTBOX, null, false );
if ( isset( $id ) )
{
if ( is_array( $id ) )
{
$this->assignVars( $id );
}
else
{
$this->load( intval( $id ) );
}
}
else
{
$this->setNew();
}
}
function load( $id )
{
$sql = 'SELECT *
FROM '.$this->db->prefix( 'dbv_persons' ).'
WHERE persons_id = ''.$id.''';
$myrow = $this->db->fetchArray( $this->db->query( $sql ) );
$this->assignVars( $myrow );
if ( !$myrow )
{
$this->setNew();
}
}
[b][color=CC0000]...[/color][/b]
}
/**
* dbv_personshandler Class
*
* This class provides simple mechanisms for dbv_persons object
*
* @author Vincent Fourastié
* @package DB Volley
* @version 1.0
*/
class Xoopsdbv_personsHandler extends XoopsObjectHandler
{
/**
* create
*
* Create a new dbv_persons
*
* @param bool $isNew Flag the new objects as 'new' ?
*
* @return object dbv_persons
*/
function &create( $isNew = true )
{
$dbv_persons = new dbv_persons();
if ( $isNew )
{
$dbv_persons->setNew();
}
return $dbv_persons;
}
/**
* get
*
* Retrieve a dbv_persons
*
* @param int $id Id of the dbv_persons
*
* @return mixed reference to the {@link dbv_persons} object, FALSE if failed
*/
function &get( $id )
{
$sql = 'SELECT *
FROM '.$this->db->prefix( 'dbv_persons' ).'
WHERE persons_id = ''.$id.''';
if ( !$result = $this->db->query( $sql ) )
{
return false;
}
$numrows = $this->db->getRowsNum( $result );
if ( $numrows == 1 )
{
$dbv_persons = new dbv_persons($id);
$dbv_persons->assignVars( $this->db->fetchArray( $result ) );
return $dbv_persons;
}
return false;
}
/**
* insert
*
* Insert a new dbv_persons in the database
*
* @param object $dbv_persons reference to the {@link dbv_persons} object
* @param bool $force
*
* @return bool FALSE if failed, TRUE if already present and unchanged or successful
*/
function insert( &$dbv_persons, $force = false )
{
global $xoopsConfig;
if ( get_class( $dbv_persons ) != 'dbv_persons' )
{
return false;
}
if ( !$dbv_persons->isDirty() )
{
return true;
}
if ( !$dbv_persons->cleanVars() )
{
return false;
}
foreach ( $dbv_persons->cleanVars as $k => $v )
{
${$k} = $v;
}
if ( $dbv_persons->isNew() )
{
$dbv_persons = new dbv_persons();
$format = 'INSERT INTO %s
( persons_id, persons_sex, persons_surname, persons_firstname,
persons_nicknames, persons_country, persons_country2, persons_birth,
persons_height, persons_birthwhere, persons_picture, persons_xoopsid,
persons_occupation, persons_lastupdate )';
$format .= 'VALUES (%u, %u, %s, %s, %s, %s, %s, %s, %u, %s, %s, %u, %u, %s)';
$sql = sprintf( $format,
$this->db->prefix( 'dbv_persons' ),
$persons_id,
$persons_sex,
$this->db->quoteString( $persons_surname ),
$this->db->quoteString( $persons_firstname ),
$this->db->quoteString( $persons_nicknames ),
$this->db->quoteString( $persons_country ),
$this->db->quoteString( $persons_country2 ),
$this->db->quoteString( $persons_birth ),
$persons_height,
$this->db->quoteString( $persons_birthwhere ),
$this->db->quoteString( $persons_picture ),
$persons_xoopsid,
$persons_occupation,
$this->db->quoteString( $persons_lastupdate ) );
$force = true;
}
else
{
$format = 'UPDATE %s
SET ';
$format .= 'persons_id = '%u',
persons_sex = '%u',
persons_surname = '%s',
persons_firstname = '%s',
persons_nicknames = '%s',
persons_country = '%s',
persons_country2 = '%s',
persons_birth = '%s',
persons_height = '%u',
persons_birthwhere = '%s',
persons_picture = '%s',
persons_xoopsid = '%u',
persons_occupation = '%u',
persons_lastupdate = '%s'';
$format .= ' WHERE persons_id = '%u'';
$sql = sprintf( $format,
$this->db->prefix( 'dbv_persons' ),
$persons_id,
$persons_sex,
$this->db->quoteString( $persons_surname ),
$this->db->quoteString( $persons_firstname ),
$this->db->quoteString( $persons_nicknames ),
$this->db->quoteString( $persons_country ),
$this->db->quoteString( $persons_country2 ),
$this->db->quoteString( $persons_birth ),
$persons_height,
$this->db->quoteString( $persons_birthwhere ),
$this->db->quoteString( $persons_picture ),
$persons_xoopsid,
$persons_occupation,
$this->db->quoteString( $persons_lastupdate ),
$persons_id );
}
if ( false != $force )
{
$result = $this->db->queryF( $sql );
}
else
{
$result = $this->db->query( $sql );
}
if ( !$result )
{
return false;
}
if ( empty( $persons_id ) )
{
$persons_id = $this->db->getInsertId();
}
$dbv_persons->assignVar( 'persons_id', $persons_id );
return true;
}
[b][color=CC0000]...[/color][/b]
}
Post édité pour supprimer les méthodes ne posant pas de problèmes
|