Using the redbean library, new fields should be added to the database, but this does not happen

124 Views Asked by At

Using the redbean library, new fields should be added to the database, but this does not happen. What is the problem, tell me please. There are no identical tables, the database is created, I use phpmyadmin.

<?php
    require "libs/rb.php";
R::setup( 'mysql:host=localhost;dbname=usersdatadb',
        'root', 'root' );
?>



$data = $_POST;
if(isset($data['email'])){
    $errors = array();
    if(trim($data['email'])==''){
        $errors[] = 'Введите email';
    }
    if(trim($data['login'])==''){
        $errors[] = 'Введите имя пользователя';
    }
    if($data['password']==''){
        $errors[] = 'Введите пароль';
    }
    if($data['enterpassword'] != $data['password']){
        $errors[] = 'Пароль введен не верно';
    }
    if(empty($errors)){
        $user = R::dispense('users');
        $user->email = $data['email'];
        $user->login = $data['login'];
        $user->password = password_hash($data['password'], PASSWORD_DEFAULT);
        
    }else{
        echo '<div class="error_div" style = "color: red;">'.array_shift($errors).'</div>';
    }
}

When I try and store with R::store(), I get the following error:

Fatal error: Uncaught PDOException: Could not connect to database (usersdatadb). in W:\domains\OLV2\php\libs\rb.php:1056 Stack trace: #0 W:\domains\OLV2\php\libs\rb.php(777): RedBeanPHP\Driver\RPDO->connect() #1 W:\domains\OLV2\php\libs\rb.php(1080): RedBeanPHP\Driver\RPDO->runQuery('show tables', Array) #2 W:\domains\OLV2\php\libs\rb.php(1101): RedBeanPHP\Driver\RPDO->GetAll('show tables', Array) #3

1

There are 1 best solutions below

0
charliefortune On

Based on the error you are getting, it is one of the following:

  • Database server is unavailable
  • DB Server hostname is incorrect
  • Database name is incorrect
  • Username/password are incorrect

Your problems are here - R::setup( 'mysql:host=localhost;dbname=usersdatadb','root', 'root' );

The rest of your code looks ok.

To follow Redbean conventions, however, you should change 'users' to singular:

$user = R::dispense('user');