$my_xpdo= new xPDO('mysql:host=localhost;dbname=mydomainname','username','password',''); if(!$my_xpdo->addPackage('ttdny','/home/sites/mydomain/public_html/core/components/ttdny/model/','ttdny_')) { return 'There was a problem adding your package! Check the logs for more info!'; } $my_items = $my_xpdo->getCollection('Towns'); $output .= '<p>Total: '. count($TownID) . '</p>'; foreach($my_items as $my_item) { $output .= '<p>Town: ' . $my_item->get('town'); $output .= '<br />Area: ' . $my_item->get('area'); $output .= '<br />Postcode: ' . $my_item->get('postcode') . '<br /></p>'; } return $output;
[classMap] => Array ( [xPDOObject] => Array ( [0] => xPDOSimpleObject [1] => AffiliateJoinSubcat [2] => FlScheduler [3] => FlgJoinListings [4] => FlgLogs [5] => Keywords [6] => ListingCategories [7] => ListingDates [8] => ListingDetails [9] => ListingHits [10] => ListingHitsShort [11] => ListingJoinFacility [12] => ListingJoinImages [13] => ListingJoinKeywords [14] => Listingratings [15] => Listings [16] => Listingstatus [17] => Listingtypes [18] => Logs [19] => NoticeboardForums [20] => NoticeboardMessages [21] => NoticeboardPosts [22] => NoticeboardTopics [23] => Postcodes [24] => SiteContent [25] => Subcategories [26] => Sysconstraints [27] => Syssegments [28] => Towns [29] => Transactions [30] => TtdnyAccountActivity [31] => TtdnyAffiliateJoin [32] => TtdnyAffiliates [33] => TtdnyAreas [34] => TtdnyCategories [35] => TtdnyFacilities [36] => TtdnyFlGroups [37] => UserJoinListings [38] => Userimages [39] => Users [40] => Userscalendar [41] => Userstatus [42] => Usertypes ) )
<object class="Towns" table="towns" extends="xPDOObject"> <field key="TownID" dbtype="int" precision="11" phptype="integer" null="true" /> <field key="Town" dbtype="varchar" precision="255" phptype="string" null="true" /> <field key="Area" dbtype="varchar" precision="255" phptype="string" null="true" /> <field key="Postcode" dbtype="varchar" precision="255" phptype="string" null="true" /> </object>
class Towns extends xPDOObject {}
require_once (dirname(dirname(__FILE__)) . '/towns.class.php'); class Towns_mysql extends Towns {}
$xpdo_meta_map['Towns']= array ( 'package' => 'ttdny', 'version' => '1.1', 'table' => 'towns', 'extends' => 'xPDOObject', 'fields' => array ( 'TownID' => NULL, 'Town' => NULL, 'Area' => NULL, 'Postcode' => NULL, ), 'fieldMeta' => array ( 'TownID' => array ( 'dbtype' => 'int', 'precision' => '11', 'phptype' => 'integer', 'null' => true, ), 'Town' => array ( 'dbtype' => 'varchar', 'precision' => '255', 'phptype' => 'string', 'null' => true, ), 'Area' => array ( 'dbtype' => 'varchar', 'precision' => '255', 'phptype' => 'string', 'null' => true, ), 'Postcode' => array ( 'dbtype' => 'varchar', 'precision' => '255', 'phptype' => 'string', 'null' => true, ), ), );
// Criteria for foreign Database $host = 'IPAddress'; $username = 'username; $password = 'password'; $dbname = 'databaseName'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $xpdo = new xPDO($dsn, $username, $password); // Test your connection echo $o = ($xpdo->connect()) ? 'Connected </br>' : 'Not Connected'; $xpdo->addPackage('ttdny','/home/sites/domainName/public_html/core/components/ttdny/model/'); $xpdo->setDebug(true); $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $members = $xpdo->getCollection('Towns'); echo 'Total: '.count($TownID);
Connected
[2012-12-15 22:34:28] (DEBUG @ /index.php)
Returning table class: Towns for class: Towns
[2012-12-15 22:34:28] (DEBUG @ /index.php)
Returning table name: `towns` for class: Towns
[2012-12-15 22:34:28] (DEBUG @ /index.php)
Returning ancestry for Towns: Array
(
[0] => Towns
[1] => xPDOObject
)
[2012-12-15 22:34:28] (DEBUG @ /index.php)
Returning ancestry for Towns: Array
(
[0] => xPDOObject
)
[2012-12-15 22:34:28] (DEBUG @ /index.php)
Attempting to execute query using PDO statement object: SELECT `Towns`.`TownID` AS `Towns_TownID`, `Towns`.`Town` AS `Towns_Town`, `Towns`.`Area` AS `Towns_Area`, `Towns`.`Postcode` AS `Towns_Postcode` FROM `towns` AS `Towns` Array
(
)
[2012-12-15 22:34:28] (ERROR @ /index.php)
Error 42S02 executing statement:
Array
(
[0] => 42S02
[1] => 1146
[2] => Table 'databaseName.towns' doesn't exist
)
Total: 0
$xpdo->addPackage('ttdny','/home/sites/thingstodonearyou.co.uk/public_html/core/components/ttdny/model/','ttdny_');
$xpdo->setDebug(true); $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML')
<object class="Towns" table="towns" extends="xPDOObject">
<field key="TownID" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="pk" />
<field key="Town" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="Area" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="Postcode" dbtype="varchar" precision="255" phptype="string" null="true" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="TownID" length="" collation="A" null="false" />
</index>
</object>
<?php $host = 'IPAdress'; $username = 'DBUsername'; $password = 'DBPassword'; $dbname = 'DBName'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $xpdo = new xPDO($dsn, $username, $password); echo $o = ($xpdo->connect()) ? 'Connected </br>' : 'Not Connected'; if (!$xpdo->addPackage('ttdny','/home/sites/domainname/public_html/core/components/ttdny/model/','ttdny_')) { print 'There was a problem adding your package.'; }; $xpdo->setDebug(true); $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $results = $xpdo->getCollection('Towns',array('TownID' => 27)); //$results = $xpdo->getCollection('Towns',27)); $output = ''; if ($results) { foreach($results as $result) { $output .= "<p>Town: " . $result->get('Town'); $output .= '<br />Area: ' . $result->get('Area'); $output .= '<br />Postcode: ' . $result->get('Postcode') . '<br /></p>'; } } else { return 'No items found.'; } echo $output;