Hi.
Excuse my English.
My first try with xPDO and I’ve got a ’Error preparing statement for query: ’...
Could someone help me?
So, I have the following scenario:
1) A database called db_learning with just one table called lear_user, that has two fields: id and name. The first is a ’int not null primary key auto_increment’, and the second a ’varchar(100)’.
2) Three files: learning.mysql.schema.xml, create_everything.php and do_things.php.
Here’s the contents:
-- learning.mysql.schema.xml --
<?xml version="1.0" encoding="UTF-8"?>
<model package="learning" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="lear_">
<object class="User" table="user" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
</object>
</model>
-- create_everything.php --
include('./xpdo/xpdo.class.php');
$dsn = 'mysql:host=localhost,dbname=db_learning';
$xpdo = new xPDO($dsn, $username='root', $password='password');
$xpdo->setDebug(true);
$xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);
$xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
$schema = '/var/www/localhost/htdocs/php/learning.mysql.schema.xml';
$target = '/var/www/localhost/htdocs/php/model/';
$generator->parseSchema($schema,$target);
* After that, the directory ’model’ is filled with some files that seems to be all ok.
-- do_things.php --
include('./xpdo/xpdo.class.php');
$dsn = 'mysql:host=localhost,dbname=db_learning';
$xpdo = new xPDO($dsn, $username='root', $password='password');
$xpdo->setDebug(true);
$xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);
$xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$xpdo->addPackage('learning', '/var/www/localhost/htdocs/php/model/','lear_');
$usuario = $xpdo->newObject('User');
$user_1 = $xpdo->getObject('User', array('id'=>19) );
print_r($user_1);
And... I get the following error:
[2010-04-21 20:27:32] (ERROR @ /php/do_things.php)
Error preparing statement for query: SELECT `User`.`id` AS `User_id`, `User`.`name` AS `User_name` FROM `lear_user` AS `User` WHERE `User`.`id` = ?
The funny stuff is I can copy and paste that SQL, change ’?’ with ’19’ and that works fine, it returns the table’s record in a MySQL console.
So, what could be my mistake?
[]s
Alexander
Brazil