PHP Classes

example.php of 0.4 package does not work

Recommend this page to a friend!

      My Active Record  >  All threads  >  example.php of 0.4 package does not work  >  (Un) Subscribe thread alerts  
Subject:example.php of 0.4 package does not work
Summary:getting an error while trying the example.php
Messages:8
Author:somekool
Date:2007-07-17 22:35:33
Update:2007-07-23 11:55:07
 

  1. example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-17 22:35:33
Of course I created a black database and set the connection string in the example.php file.

Here is the output....
=============================== BEGIN ================================
Created `car` Table
Created `driver` Table
Created `car_driver` Table

Fatal error: MyActiveRecord::Class2Table - Class Driver does not have a table representation in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 273
================================ END =================================
line 273 is the trigger_error line in this function.

function Class2Table($mxd)
{
$origClass = is_object($mxd) ? get_class($mxd) : $mxd;
class_exists($origClass)
or trigger_error("MyActiveRecord::Class2Table - Class $origClass does not exist", E_USER_ERROR);
$class = $origClass;
while( !MyActiveRecord::TableExists( strtolower($class) ) && $class !='MyActiveRecord' )
{
$class = get_parent_class($class);
}
$table = strtolower($class);
if($table=='myactiverecord')
{
trigger_error("MyActiveRecord::Class2Table - Class $origClass does not have a table representation", E_USER_ERROR);
return false;
}
return $table;
}


what is it that am I missing?

please help.

  2. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-17 22:50:37 - In reply to message 1 from somekool
after a couple of refresh.... I am not getting this output...


Warning: MyActiveRecord::Query() - query failed: SELECT driver.* FROM driver INNER JOIN car_driver ON driver_id = driver.id WHERE car_driver.car_id = 1 ORDER BY Driver.id with error: Unknown column 'Driver.id' in 'order clause' in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 184

Fatal error: MyActiveRecord::FindBySql() - SQL Query Failed: SELECT driver.* FROM driver INNER JOIN car_driver ON driver_id = driver.id WHERE car_driver.car_id = 1 ORDER BY Driver.id in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 585


please help as I would like to start using this library as fast as possible.

thanks


  3. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-17 22:53:14 - In reply to message 2 from somekool
spelling in first message

BLANK database (not black)

spelling in second message

I am NOW getting this output... (not not)


  4. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-18 00:17:37 - In reply to message 1 from somekool
I tried on two different server

PHP Version 5.1.6-pl11-gentoo

and

PHP Version 5.2.2

and it's totally reproducable

delete the tables. first hit. the 3 tables gets created and you get this error message

Fatal error: MyActiveRecord::Class2Table - Class Driver does not have a table representation in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 273

it crashed on
foreach( MyActiveRecord::FindAll('Driver') as $driver ) $driver->destroy();

while the previous FindAll with Car worked?????

second hit. you get these two errors

Warning: MyActiveRecord::Query() - query failed: SELECT car.* FROM car INNER JOIN car_driver ON car_id = car.id WHERE car_driver.driver_id = 2 ORDER BY Car.id with error: Unknown column 'Car.id' in 'order clause' in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 184

Fatal error: MyActiveRecord::FindBySql() - SQL Query Failed: SELECT car.* FROM car INNER JOIN car_driver ON car_id = car.id WHERE car_driver.driver_id = 2 ORDER BY Car.id in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 585

which happens on the call of this line.

$jana->set_attached('Car', array($c4->id, $ka->id));

then 3rd hit.....

you get the following two errors

Warning: MyActiveRecord::Query() - query failed: SELECT driver.* FROM driver INNER JOIN car_driver ON driver_id = driver.id WHERE car_driver.car_id = 1 ORDER BY Driver.id with error: Unknown column 'Driver.id' in 'order clause' in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 184

Fatal error: MyActiveRecord::FindBySql() - SQL Query Failed: SELECT driver.* FROM driver INNER JOIN car_driver ON driver_id = driver.id WHERE car_driver.car_id = 1 ORDER BY Driver.id in /home/somekool/Sites/midosan-flowchart/MyActiveRecord.0.4.php on line 585

which happens on the first FindAll

foreach( MyActiveRecord::FindAll('Car') as $car ) $car->destroy();


  5. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-18 07:11:12 - In reply to message 4 from somekool
I fixed the last two hit of errors by replacing the line 1131 of the MyActiveRecord class

it's now

$strOrder = $strOrder ? $strOrder: "{$table}.id";

my MySQL must have case sensitive table enabled. this is more proper anyway IMO.

the first error still occurs. I tried fixing it but I don't know I cannot find the problem. the table exist at the point of the query but Class2Table cannot find it.


  6. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-18 08:35:33 - In reply to message 5 from somekool
ok, I have been using MyActiveRecord all day and I must say, it's real sweet. I like it. I just have one intermittent bug now. it works most of the time, but sometimes,... the exact same code will not work.

I am simply doing a

MyActiveRecord::FindAll('Question', 'answer_id=0');

and while most of the times it returns me correct info, sometimes I get an unexisting row instead.

anyone else had strange problem like that?


  7. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of somekool somekool - 2007-07-18 08:45:08 - In reply to message 6 from somekool
after further debugging, I realized it actually gets the correct row from the database. the 'content' column has the correct info. but the id is equal to 1 instead of 5. there is no row with id=1 in the DB.


  8. Re: example.php of 0.4 package does not work   Reply   Report abuse  
Picture of Jake Grimley Jake Grimley - 2007-07-23 11:55:07 - In reply to message 7 from somekool
Hi there,

Sorry for the slow response. I've been on holiday and have come back to a mountain of email!

It sounds like you've found a new bug with regard to case sensitive tables. I thought I had squashed all of these!

Will investigate and post fix. Not sure if your ID problem is related.

ATB
Jake.