EzDevInfo.com

notorm

NotORM - PHP library for simple reading data from the database NotORM - PHP library for simple working with data in the database notorm is a php library for simple reading data from the database. the most interesting feature is a very easy work with table relationships.

Select a date larger than today using NotORM

I have a vey simple query (or so I thought) using NotORM:

$query = $db-> irregular
    ->select('id','name','starttime','endtime')
    ->where('customer_id',$_SESSION['user']['customer_id'])
    ->where("startdate > ? ", new NotORM_Literal("NOW()")) );

The "?" doesn't get replaced in the above instance. The query just reads

SELECT id, name, starttime, endtime FROM irregular WHERE (customer_id = '1') AND (startdate > ? )

How is this meant to work in NotORM?


Source: (StackOverflow)

RedBeanPHP, NotORM and DibiPHP. Which one of these simple ORM is the best? [closed]

I am looking for a simple ORM for PHP for a small project. I found 3 of them. Do you have any idea of which one is the best?

http://redbeanphp.com

http://www.notorm.com

http://dibiphp.com

I appreciate any help. Thanks.


Source: (StackOverflow)

Advertisements

Declare a delete statement in NotORM

How to declare a Delete statement in NotORM like this code: mysql_query("DELETE FROM pspaym WHERE F4='$d' ");


Source: (StackOverflow)

php serialize function parsing error

i have this array

$x = array(
    1 => 16,
    2 => 8
);

and

$y = serialize($x);

i'm using notorm and now this query

$db->table()->update(array('config' => $y));

the query

update table set config = 'a:2:{i:1;i:16;i:2;i:8;}'

but in the table

a?:{i?;s?:"16";i?;s?:"8";}

now the question is what's happend to the serialize


Source: (StackOverflow)

NOTORM custom mysql function

How can I select a custom value calculated from an existing field ?

For example, I'm storing date of birth, and I would like to select the age, calculated from a mySql function.

$app->get("/users/:id", function ($id) use ($app, $db) {
$user = $db->users()->where("users_id", $id);
if ($data = $user->fetch()) {
    $hobbies = array();
    foreach ($data->users_hobbies() as $hobbie) { // get all tags of $application
        $hobbies[] = $hobbie["users_hobbies_name"]; // print the tag name
    }
    echo json_encode(array(
        "id" => $data["users_id"],
        "login" => $data["users_login"],
        "mail" => $data["users_mail"],
        "date_of_birth" => $data["users_date_of_birth"],
        "age" => ??
        "hobbies" => $hobbies
        ));
} else {
    echo json_encode(array(
        "status" => false,
        "message" => "User ID $id does not exist"
        ));
}
});

Source: (StackOverflow)

SQL Query return zero row using notORM php

Issue: SQl Query return zero row using notORM.

Steps taken to fix it but didnt work:

  1. Check connection db -> no error, connection established
  2. Check instance initialization -> obj inst. created succesfully
  3. Check syntax -> no error
  4. Check table name exist || !exist -> table name exist
  5. Check no. of row in table rates_call either rows > 0 || = 0 -> no. of rows > 0

Code:

require 'NotORM.php';
$conn = new PDO($dsn, $db_username, $db_password) or die ("can't connect");
$db = new NotORM($conn) or die ("instance not created");
$rates = array();
foreach($db->rates_call() as $rate)   
{ 
   $rates[] = array(
    "country_name" => $rate[country_name],
    "rate" => $rate[rates] 
   ); 
   echo "in foreach loop";
}
echo json_encode($rates);

Based on the code, the foreach loop not executed bcoz the no. of row returned is zero but in my database table, having few line of rows. I already tried using PDO aswell, it returned zero result also. Appreciate your assistant.


Source: (StackOverflow)

NotORM with existing class

I'm looking in to using NotORM for a project (no code has been written yet).

I get that NotORM can make an object based on MySQL tables. What I don't quite understand is how I use it if I have an existing class in place. Should I inject NotORM in to the class? But then how do I use it to load/save from the db?

I guess the main problem I am trying to understand is if I have a class that I save to the db over multiple tables (let's call it MyClass), I understand why an ORM is a good idea, as the class may be stored over multiple tables in the db, but what if MyClass has some methods that do other stuff (for example maybe it talks to an external api elsewhere)? Just loading straight from the db using NotORM is not going to make the same 'MyClass' - from what I understand it will only have the data from the db.


Source: (StackOverflow)

PHP NotORM foreign key data not picked up

this is my first introduction with NotORM and i'm unable to print foreignkey data Here are my tables:

**userinfo**
id , int (primary key, autoincrement)
username , varchar(50)
gender , varchar(6)
password , varchar(50)

**budgetinfo**
entryid , int (primary key, autoincrement)
userid int references userinfo(id)
amount , varchar(50)
entrydate , varchar(6)

Here is my NotORM code:

<?php

require "NotORM.php";

$dsn = "mysql:dbname=budget;host=127.0.0.1";
$pdo = new PDO ( $dsn, "root", "root" );
$budgetdb = new NotORM ( $pdo );
?>

The code lists the records but didn't print the budgetinfo entry

Please tell me what's wrong i'm doing

<br/><br/>
<hr/>
Listing records, userinfo(id) => pk , budgetinfo(userid) => fk
<hr/>

<?php 
$userinfos = $budgetdb->userinfo();

if(isset($userinfos) && count($userinfos)>0){
    foreach ( $userinfos as $userinfo ) {
        echo $userinfo ["username"] . " " . $userinfo ["gender"] . "<br/>";

        $budgets = $userinfo->budgetinfo();

        if(isset($budgets) && count($budgets)>0){
            foreach ($budgets as $budget)
                echo $budget->budgetinfo["amount"] . " , " . $budget->budgetinfo["entrydate"] . "<br/>";
        }
        else
            echo "No budgets set...";

        echo "<br/>-------------------------------<br/>";
    }
}
else
    echo "No record found...";
?>

Source: (StackOverflow)

update a single record in NOTORM

I am trying to update a single record using the NOTORM library. I have a userID and need update the password column. I cannot find any code examples for just updating one record. here is the code have now which does not work it updates every record instead of the just one with the right userID.

$dbdata = array(
"Password" => $password
);
$result =  $db->$databasetable->where("id = ?", $userdata['UserID'])->update($dbdata);

echo $result;

Source: (StackOverflow)

How do I JOIN many-to-many tables using NotORM

I'm learning NotORM to produce a simple system for school. I want to be able to award 'Pledges' to 'students'. Here is my data structure:

My tables:

students

  • -studentid (PK) -firstname -surname -dateofbirth -vmg -yeargroup

link

  • -linkid (PK) -studentid (FK) -pledgeid (FK) -timeofaward

pledges

  • -pledgeid (PK) -pledgename -pledgeinfo

The code from a great NotORM tutorial (http://www.sitepoint.com/database-interaction-made-easy-with-notorm/) says that I should do this:

<?php
foreach ($books as $book) {
echo "<tr>";
echo "<td>" . $book["title"] . "</td>";
echo "<td>" . $book["author"] . "</td>";
// book_category table joins book and category
$categories = array();
foreach ($book->book_category() as $book_category) {
    $categories[] = $book_category->category["category"];
}
echo "<td>" . join(", ", $categories) . "</td>";
echo "</tr>";
}
?>
  1. Is my data structure correct for using NotORM
  2. How do I translate the example so that it shows the students and which awards have been awarded to them. - I feel like I have tried every variation of that code and still can't get it to work.

Many thanks in advance.


Source: (StackOverflow)

How do I JOIN one-to-many tables using NotORM lib

i'm using NotOrm lib for working with data in the database. I have to follow the instructions here http://www.sitepoint.com/database-interaction-made-easy-with-notorm/

but did not solve my problem Here is my data structure:

Tables 
   -members 
           ---Indexes 
            PRIMARY id 

   -cards
          ---Indexes 
            PRIMARY id
            INDEX   member_id
          ---Foreign keys
            member_id   members(id) CASCADE CASCADE

I used sql command

ALTER TABLE  `cards` ADD FOREIGN KEY (  `member_id` ) REFERENCES  `xxx`.`members` (`id`)
     ON DELETE CASCADE ON UPDATE CASCADE ;

my code

$cards = $this->db->cards();    
    foreach($cards as $c){
        //echo "here";
        echo $c->members["member_id"];
    }

and response is

=> Message: Undefined index: members_id

Is my data structure correct for using NotORM ? i want to result from SQL as:

select members.f1, members.f2 from members join cards on members.id = cards.member_id where cards.email like '%%' or cards.phone like '%%'

Many thanks!


Source: (StackOverflow)

Debugging NotORM Call Results in "Use of undefined constant STDERR - assumed 'STDERR'"

I am debugging a project that uses Slim and NotORM on PHP 5.4. When setting NotORM to debug mode the NotORM trace statement:

fwrite(STDERR, "$backtrace[file]:$backtrace[line]:$debug\n");

throws the following error:

"Use of undefined constant STDERR - assumed 'STDERR'"

I have a feeling the problem is Slim as the error message does not show up when executing Php command line scripts.

Does anyone know how to fix this issue (preferably without modifying NotORM)?

Thanks in advance.


Source: (StackOverflow)

Need a simple ORM or DBAL for existing PHP app

I am working on extending an existing PHP application. Unfortunately for me, the existing app is a mess. It's all spaghetti code with raw mysql_* calls. Groan. No way that I am going to do that in the parts that I am extending.

So, I am looking for a simple ORM of DBAL that I can easily drop in and start using. Desired features:

  • It must work on an existing database schema. Preferably with minimal or no additional configuration. The existing database schema is the same quality as the existing PHP code (no sensible naming conventions, not normalised, etc.). I don't want to spend days converting the database schema manually into annotated object properties a la Doctrine 2.
  • It must be able to work alongside the existing raw mysql_* queries. I have no idea how hydrating ORMs like Doctrine 2 or Propel behave when scripts are manually manipulating the data in the database behind their backs, but I assume it's not pretty.
  • It must run on PHP 5.2.x. I'd love to use PHP 5.3 but I have zero interest in going over the existing 125K lines of spaghetti code mess to make sure it runs on PHP 5.3.
  • Relationships not required. In the few places I need to get to relational data, I'll be happy to call an extra find() or query() or whatever myself.
  • Bonus points if it has some trigger support (e.g. beforeSave, afterSave). Not a requirement, but just nice to have.

Edit: Someone put me out of my misery. I just found out that the 125K lines of spaghetti code also changes the database schema. E.g, add an extra option somewhere and a whole slew of ALTER TABLE statements start flying. I could probably fill a year's worth of TheDailyWTF with this codebase. So, one more requirement:

  • Must be able to cope with a changing database schema automatically (e.g. adding columns).

I have been looking at a few solutions, but I am unsure how well they would work given the requirements. Doctrine 2, RedBeanPhp and the like all require PHP 5.3, so they are out. There's a legacy version of RedBeanPhp for PHP 5.2.x but I don't know if it would work with a messy, existing database schema. NotORM looks okay for getting data out but I don't know if it can be configured for the existing database schema, and how you can easily put data back into the database.

Ideally I would like something simple. E.g:

$user = User::find($id);
$user->name = 'John Woo';
$user->save();

Or:

$articles = ORM::find('article')->where('date' => '2010-01-01');
foreach ($articles as $article) {
    echo $article->name;
}

Any tips or even alternative solutions are welcome!


Source: (StackOverflow)

NotORM: How to fetch data?

I´m having trouble using selects, I tried reading the documentation but it's not too clear, and the forums that talk about it are few and inactive.

I want to do a simple select, so I tried:

$applications = $NOTORM->user_types()
                        ->select('id, group_title')
                        ->where('id', 1);
return $applications;

That however gives me back a NotORM object where I don't see the resulting rows that I get when I do a normal: SELECT id, group_title FROM user_types WHERE id = 1

I tried using the fetch() but not really sure how to use it. Any insights?


Source: (StackOverflow)

Selecting distinct column values in NOTORM

My MySQL table look like this:

 'id'       'name'    'type'
 1           name1       A         
 2           name2       B 
 3           name3       A  
 4           name4       C 
 5           name5       C

How can I get all distinct types i.e A, B, C in NOTORM PHP.


Source: (StackOverflow)