当前位置: 首页>>代码示例>>PHP>>正文


PHP ADODB_Active_Record::TableHasMany方法代码示例

本文整理汇总了PHP中ADODB_Active_Record::TableHasMany方法的典型用法代码示例。如果您正苦于以下问题:PHP ADODB_Active_Record::TableHasMany方法的具体用法?PHP ADODB_Active_Record::TableHasMany怎么用?PHP ADODB_Active_Record::TableHasMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ADODB_Active_Record的用法示例。


在下文中一共展示了ADODB_Active_Record::TableHasMany方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: NewADOConnection

<?php

include_once '../adodb.inc.php';
include_once '../adodb-active-record.inc.php';
$db = NewADOConnection('mysql://root@localhost/northwind');
$db->debug = 1;
ADOdb_Active_Record::SetDatabaseAdapter($db);
$db->Execute("CREATE TEMPORARY TABLE `persons` (\r\n\t                `id` int(10) unsigned NOT NULL auto_increment,\r\n\t                `name_first` varchar(100) NOT NULL default '',\r\n\t                `name_last` varchar(100) NOT NULL default '',\r\n\t                `favorite_color` varchar(100) NOT NULL default '',\r\n\t                PRIMARY KEY  (`id`)\r\n\t            ) ENGINE=MyISAM;\r\n\t           ");
$db->Execute("CREATE TEMPORARY TABLE `children` (\r\n\t                `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\t`person_id` int(10) unsigned NOT NULL,\r\n\t                `name_first` varchar(100) NOT NULL default '',\r\n\t                `name_last` varchar(100) NOT NULL default '',\r\n\t                `favorite_pet` varchar(100) NOT NULL default '',\r\n\t                PRIMARY KEY  (`id`)\r\n\t            ) ENGINE=MyISAM;\r\n\t           ");
$db->Execute("insert into children (person_id,name_first,name_last) values (1,'Jill','Lim')");
$db->Execute("insert into children (person_id,name_first,name_last) values (1,'Joan','Lim')");
$db->Execute("insert into children (person_id,name_first,name_last) values (1,'JAMIE','Lim')");
ADODB_Active_Record::TableHasMany('persons', 'children', 'person_id');
class person extends ADOdb_Active_Record
{
}
$person = new person();
#	$person->HasMany('children','person_id');  ## this is affects all other instances of Person
$person->name_first = 'John';
$person->name_last = 'Lim';
$person->favorite_color = 'lavender';
$person->save();
// this save will perform an INSERT successfully
$person2 = new person();
$person2->Load('id=1');
$c = $person2->children;
if (is_array($c) && sizeof($c) == 3 && $c[0]->name_first == 'Jill' && $c[1]->name_first == 'Joan' && $c[2]->name_first == 'JAMIE') {
    echo "OK Loaded HasMany</br>";
} else {
    var_dump($c);
    echo "error loading hasMany should have 3 array elements Jill Joan Jamie<br>";
开发者ID:tamtrong,项目名称:testlink,代码行数:31,代码来源:test-active-relations.php


注:本文中的ADODB_Active_Record::TableHasMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。