php – creates a variable with a database field

I have the following code;

$ sql = "SELECT *
FROM user
WO login = & # 39; "$ login." & # 39; AND password = & # 39; "$ pass." & # 39; ";
// Ask for a table
$ exists = mysqli_query ($ bindBD, $ sql);
// Number of records resulting from SQL
$ num_registos = mysqli_num_rows ($ exists);

My question is how to log on, create a variable such as $ login, and get the same variable as the value of the database logon field.

Database Design – Non-cluster index stores the cluster key instead of the RID

I have read a textbook that says:

Remember that the clustered index defines the actual physical order of the data rows on disk, so if a row is updated so that its cluster key changes, that row must be moved to a page where it is sorted correctly stored in a non-clustered index (as on a heap), the RID for that row would change, and every single nonclustered index would have to be updated. "

I understand the point, but if the cluster key of a row changes, should not the leaf nodes of the non-clustered index also be updated? Is not this the same effort as updating RID?

And when the cluster key of a line changes. Only the leaf nodes (not the root or intermediate nodes) need to be updated with the latest cluster key, right?

Existing user deleted items in a database

I'm creating a web application where users have their own topics. Since topics are recorded for reporting purposes, it is important that previously used topics are not deleted so that they can be referenced in future reports.

In my relational database, topics are assigned to users via a user identification, I want users not to delete a topic, but to orphan by setting it user identification to zero, In this way, the topic can be referenced in reports by ID, but it is deleted from the user's perspective.

Is this a good practice? Should I move the topics to one instead? Deleted_Topics Table?

Technology – storage of statistical data in the database

I have several similar threads (primitive bots) in the application. Bots perform some actions until the goal is reached. I want to record each step of the thread in the database for later parsing.

Each bot has a unique identifier and I also provide it with the timestamps. The record looks like this

recording
bot_id
area_id
x_position
y_position
Group ID
time stamp

However, I do not want to block the thread while trying to save the data in the database. That's why I decided to send messages to a news broker and then use a separate process that reads these messages and stores them in the database.

But I can not decide on a technology. As far as I can understand, I can use anyone for my case – I can use any broker, can use any database (from relational to not). I like to experiment with different tools.

So what could you recommend that would be effective for my case?

8 – The username must match a number from a specific database table

I work at a telephone and internet provider. Our users are identified by their personal ID number (this is not the case in the US, everyone has an ID card designated by the government as DNI).

I set up the company's website in Drupal and develop an application that shows registered users what services they have, what bills they have, etc.
I have been asked to do the user registration as follows: Users need to register as their username with their DNI number, and the program must confirm that this DNI number belongs to an actual user (I have a user table). If not, the registration should be rejected.

Any ideas how this can be achieved?

Database Theory – Limitations of the ** Reservoir Sampling Algorithm ** in a DBMS

I try the idea of Reservoir sampling algorithm, The article on Wikipedia gives the following example:

If we have a sample size of $ s = $ 10, then the probability is that $ 9 ^ {th} $ Item is added to the sample $ 1 $ there is still room left. If the $ 11 ^ {th} $ Article arrives, the probability is that it will be added and replace an old article (random position) $ frac {10} {11} $, Here, the likelihood that an item will be replaced at a given position is the same $ frac {1} {10} $, Again, if that $ 12 ^ {th} $ Article arrives, is the probability that it will replace an existing article $ frac {10} {12} $, It is clear that with every other article that comes after $ 10 ^ {th} $ Point, the probability that it will be added to the sample decreases, while the probability that the old sample remains the same increases. From this I can conclude that at $ 1101 ^ {th} $ When the article arrives, the likelihood that it will be added to the sample is very high $ frac {10} {1101} = 0.0090826521 % $,

In another scenario, if our sample size $ s = $ 100,000 and we process that $ 25,898,750 ^ {th} $ item, the likelihood that the new article will be added to the sample and will replace a random existing article $ frac {100,000} {25,898,750} = 0,0038611902 % $

First, I think that my understanding of the topic is correct, but, moreover, this method is a viable solution if, for example, we have a very large sample $ s = $ 10 million? Which restrictions are there then?

Java Database Structure – Code Review Stack Exchange

In order to stay in practice with good Java programming techniques, I have decided to write a database. It stores only employees, allows logged in users to retrieve / hire employees, and has a sign-in mechanism that prevents the use of methods when you are not logged in. I'm looking for feedback in the following areas:

  • structure Is the overall structure of the program good? Are there any improvements that can make the structure of the program more efficient / compact?
  • Login mechanism Is the way I implemented this system alright? Is there a better way to implement this login system?
  • exceptions I have created two custom exceptions for this program. Is the way I coded these exceptions acceptable? Should I have had one? Custom exception Class from which they could inherit so that I can only have the message print error message as parameter / hard coded? I use darkness when writing these exceptions, so that the serialVersionUID is generated automatically.
  • Efficiency / compactness Is there a way to make this program more efficient? Just like that getHighestSalary Method in the Database class.

All suggestions are asked and appreciated. Style and other cleanliness tips are also recommended.

Database.java

Package database;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Database {

private ArrayList employees;
private final string username;
private final string password;
private boolean logged in;

public database () {

this.employees = new ArrayList();
this.username = generateUsername ();
this.password = generatePassword ();
this.loggedIn = false;

populateEmployees ();
}

public void addEmployee (Employee employee) triggers LoginException {
if (logged in) {
this.employees.add (staff);
sortEmployees ();
Return;
}
trigger new LoginException ("Not logged in!");
}

public Employee getHighestSalary () triggers LoginException {
if (logged in) {
Employee highest = this.employees.get (0);
for (Employee Employee: this.employees) {
if (employee.getSalary ()> highest.getSalary ()) {
highest = employee;
}
}
return the highest;
}
trigger new LoginException ("Not logged in!");
}

@SuppressWarnings ("deactivated")
public void sortEmployees () triggers LoginException {
if (logged in) {
Collections.sort ((List) this.employees);
Return;
}
trigger new LoginException ("Not logged in!");
}

public Employee getEmployee (String name) triggers EmployeeNotFoundException, LoginException {
if (logged in) {
for (Employee Employee: this.employees) {
if (employee.getName (). equals (name)) {
Return employee;
}
}
Trigger new EmployeeNotFoundException ("Employee Not Found!");
}
trigger new LoginException ("Not logged in!");
}

// filler for tester class
private void populateEmployees () {
for (int i = 0; i <10; i ++) {
this.employees.add (new employee ("Employee" + i));
}
}

public void login (string username, string password) {
if (this.username.equals (username) && this.password.equals (password)) {
this.loggedIn = true;
}
}

public ArrayList getEmployees () triggers LoginException {
if (logged in) {
Give this back.
}
trigger new LoginException ("Not logged in!");
}

// used for testing
private string generateUsername () {
return "username123";
}

// used for testing
private string generatePassword () {
return "password123";
}

}

Employee.java

Package database;

public class employee {

private final string name;
private int age;
private int salary;


public employee (String name) {
this.name = name;
}

public employee (string name, int age) {
this.name = name;
this.age = age;
}

Public employee (string name, int. Age, int. Salary) {
this.name = name;
this.age = age;
this.salary = salary;
}

public String getName () {return this.name; }
public int getAge () {return this.age; }
public int getSalary () {return this.salary; }

public String toString () {
return "name:" + this.name;
}

}

LoginException.java

Package database;

public class LoginException extends Exception {

private static final long serialVersionUID = 1L;

public LoginException (String message) {
great (message);
}

public void printErrorMessage () {
System.out.println ("LoginException: Not logged in!");
}

}

EmployeeNotFoundException.java

Package database;

public class EmployeeNotFoundException extends Exception {

private static final long serialVersionUID = 1L;

public EmployeeNotFoundException (String message) {
great (message);
}

public void printErrorMessage () {
System.out.println ("EmployeNotFoundException: The employee was not found!");
}

}

Tester.java

Package database;

public class testers {

@SuppressWarnings ("unused")
public static void main (String[] Arguments) {
Database database = new Database ();
database.login ("username1234", "password123");

// Should `LoginException` trigger
To attempt {
for (employee employees: database.getEmployees ()) {
System.out.println (employee);
}
} catch (LoginException e) {
e.printErrorMessage ();
}

// Should `EmployeeNotFoundException` trigger
To attempt {
Employee test = database.getEmployee ("Ben");
} catch (EmployeeNotFoundException e) {
e.printErrorMessage ();
} catch (LoginException e) {
e.printErrorMessage ();
}

}

}

Select the database type (RDBMS or JSON) for attribute storage

Which database should be selected for storage? Now I'm thinking about PostgreSQL or MongoDB.

You have to search for attributes.

for example
created (date and time)
last update (date / time)
lastCheck (date and time)
Status (logical) – active.

The first option
[objectId] | [name] | [value]
Problem in finding value type.

The second option
[objectId] | [name] | [type] | [valueString] | [valueInt] | [ValueDateTime]
Various

The third option with MongoDB (Experience has shown that replacing the whole document is a problem, each attribute change overwrites the entire document)
[object] -> attributes.

Many ask:
Select lastCheck> = now