我目前正试图获取medoo框架,以便我可以开始轻松地从我的MySQL数据库检索数据…由于某些原因,它不起作用!
这是我的sign .php文件的代码<?php
function loginUserAccount($loginname, $password){
// Include Medoo (configured)
require_once 'medoo.min.php';
// Initialize
$database = new medoo();
$email = $database->get('MM_Users', 'Email', [
'ID' => 1
]);
return $email;
}
?>
和错误:
解析错误:语法错误,unexpected 'require_once' (T_REQUIRE_ONCE), expect function (T_FUNCTION) in /myfiledirectory/example.php on line 4
任何帮助都非常感谢!我不太清楚出了什么问题。
正在运行的php文件是:
<?php
require_once('signin.php');
if(!loginUserAccount('bobby@gmail.com', 'AveryRandomPassword')){
echo 'error';
} else {
echo $email;
}
?>
require_once的包装也有不同…这没什么区别,对吧?如果是这样,那么在生产环境中使用哪一个更可取呢?
在没有函数的类中不能有require_once
。这是主要原因。
试着把require_once
放到construct
中。
确切地说:
class foo
{
require_once('bar.php');
}
将抛出错误。
这一行:
require_once('signin.php');
在类内但在方法外,这在PHP中是不可能的。
我可能错了,但不需要require_once 'medoo.min.php';需要括号吗?像这样:require_once("medoo.min.php");
试试这个,它可能会工作
<?
require_once 'medoo.min.php';
use MedooMedoo; //If this line raises errors, remove it
// Initialize DB
$database = new Medoo(
// required
'database_type' => 'mysql',
'database_name' => 'name',
'server' => 'localhost',
'username' => 'your_username',
'password' => 'your_password',
);
$email = $database->get('MM_Users', 'Email', [
'ID' => 1
]);
return $email;
}
?>
我注意到的另一个错误是,您使用小写的M实例化了Medoo对象(换句话说,您调用了Medoo类),而这不应该是这种情况。此外,请记住传入正确的Database &服务器值。如果你仍然在这方面面临挑战,请参阅此获取更多信息。