I just want to create an application using Slim Framework and RedBeanPHP4, i'm using mysql and the name of database is 'test_api',the db has been created with empty table as my knowledge when using redbeanphp, we could create table on-the-fly. and here is my short code :

<?php   

require 'vendor/autoload.php';

// DB  
require 'db/rb.php'; 
R::setup('mysql:host=localhost;dbname=test_api', 'root','mypassword'); 
R::freeze(true);

// SLIM  
$app = new \Slim\Slim();

$app->get('/post', function () use ($app) {     
$post = R::dispense('post');
$post->text = 'Hello World';

$id = R::store($post);
echo $id; 
});

$app->run();  
?>

but i got an error like this :

    Slim Application Error 
    The application could not run because of the following error:

    Details

    Type: RedBeanPHP\RedException\SQL  
    Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test_api.post' doesn't exist  
    File: /srv/http/prj/lpse2/db/rb.php  
    Line: 631

can anybody here that will help me to solve this issues ?

2

There are 2 answers

0
mathematix On BEST ANSWER

I had the same problem with RedBeanPHP (4.2)

RedBeanPHP\Facade::dispense('MY_TABLE')
Invalid type: MY_TABLE

... even if the table already exists in the DB.

I recently found "a solution":

  1. Edit the file "rb.php" at line 10445 (version 4.2)
  2. Replace this portion of code:

     if ( !preg_match( '/^[a-z0-9]+$/', $type ) ) {
        throw new RedException( 'Invalid type: ' . $type );
     }
    

by this:

     if ( preg_match( '/^[0-9]+$/', $type ) ) {
        throw new RedException( 'Invalid type: ' . $type );
     }

IMO, the exception raised by RB comes from the capital letters of the table name.

0
Jeremy Schaffer On

If your still wanting ReadBean to change the schema to (create the table on-the-fly) then it needs to be in fluid mode. This is the default mode, but you explicitly changed it R::freeze(true);

When the mode is set to freeze it cannot modify the schema. You only need to set R::freeze(true); in production after the schema has been created.