简体   繁体   English

从php mysql中的另一个视图创建视图

[英]Create View from another view in php mysql

I am trying to create a view from another view from php and im not getting any error but it simple does not create a view. 我正在尝试从php的另一个视图创建一个视图,即时消息没有收到任何错误,但它简单地不会创建一个视图。 I can manually create view from another in the mysql console but not from php. 我可以从另一个在mysql控制台中手动创建视图,但是不能从php中创建视图。 Any idea where I am going wrong? 知道我要去哪里错了吗?

function createTransaction_file($db,$file_id){

      $sql = "CREATE VIEW transaction_file AS SELECT context,transaction_type,starttime,stoptime,stoptime - starttime AS runtime,correlator,parent_correlator,iteration FROM transactions WHERE file_id =" . $file_id . " ORDER BY starttime" ;

      //echo $sql;

      if($stmt = $db->prepare($sql)){

         /* execute query */
         $stmt->execute();
      }else{

       echo "File id is ". $file_id;

       echo "Error code ({$db->errno}): {$db->error}";

       die("Could not create transaction_iter view");
    }

    /* close statement */
    $stmt->close();

}

function createTransaction_iter($db,$iteration){

      $sql = "CREATE VIEW transaction_iter AS SELECT context,transaction_type,starttime,stoptime,stoptime - starttime AS runtime,correlator,parent_correlator,iteration FROM transaction_file WHERE iteration = ".$iteration." LIMIT 500;" ;

      //echo $sql;

      if($stmt = $db->prepare($sql)){

         /* execute query */
         $stmt->execute();


      }else{

       echo "File id is ". $file_id;

       echo "Error code ({$db->errno}): {$db->error}";

       die("Could not create transaction_iter view");
    }

    /* close statement */
    $stmt->close();

}

createTransaction_file($db,$file_id);
createTransaction_iter($db,$iteration);

I think you are simply not getting the details of the error back. 我认为您根本无法获取错误的详细信息。 Again, that if/else block is not what you meant to do I believe. 同样,我认为,如果/否则阻止不是您的意思。 Try something like this: 尝试这样的事情:

$stmt = $db->prepare($sql);

if (! $stmt->execute()) {
    $arr = $stmt->errorInfo();
    print_r($arr);
}  

UPDATE: So as expected that error message suggests a lack of required permissions for your user. 更新:因此,正如预期的那样,该错误消息表明您的用户缺少所需的权限。 I'm guessing your views were created with different rights. 我猜您的视图是用不同的权限创建的。 Here is a similar SO posting: mysql forgets who is logged in: command denied to user ''@'%' that discusses how you can get insight into the rights of those views/tables. 这是类似的SO发布: mysql忘记了谁登录:用户``@'%'被拒绝的命令,该命令讨论了如何了解这些视图/表的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM