【发布时间】:2018-04-18 07:59:51
【问题描述】:
我将redbean 5.1.0 与mariadb 和php 一起使用。
我正在尝试使用 RedBeanPHP 将一个 bean 属性(或数据库中的列)设置为 UNIQUE。
根据 RedBeanPHP 官方文档,以及许多 Google 和 StackOverflow 文章,解决方案是使用函数setMeta(...),但不幸的是它不起作用。
这是我为测试我的问题而编写的代码。
<?php
include 'rb.php';
R::setup('mysql:host=localhost;dbname=test', 'root', '');
R::nuke();
// =====================================
$bean = R::dispense('bean');
$bean->name = 'any';
$bean -> setMeta('buildcommand.unique', array(array('name')) );
R::store($bean); // No problem here. As expected :-)
// =====================================
$another_bean = R::dispense('bean');
$another_bean->name = 'any';
R::store($another_bean); // it works !!, but it shouldn't. Exception expected :-(
?>
根据另一个谷歌点击,我也尝试过 setMeta(...) 的其他选项,尽管我认为它们已被弃用。无论如何,它们也不起作用。
$bean -> setMeta('buildcommand.unique.0', array('name') );
...也与...
$bean -> setMeta('sys.uniques', array('name') );
...很多人喜欢这些。还尝试使用另一个模式(不是“测试”)。我认为这可能与缺乏执行“ALTER TABLE”的权限有关,但事实并非如此
还激活了...
R::debug(true)
...但我根本没有看到 RedBeanPHP 尝试执行“ALTER TABLE”。
感谢您的帮助
【问题讨论】:
标签: redbean mariadb php php mariadb redbean