douxiongye5779 2014-11-16 10:00
浏览 71
已采纳

Redbean + Slim Framework问题,RedBeanPHP \ RedException \ SQL SQLSTATE [42S02]:未找到基表或视图:1146表'test_api.post'不存在

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条回答 默认 最新

  • douqie1816 2015-09-13 19:12
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料