As you’ve already spoken of PHP I’ll give a minimal example using PHP + Mysql.
Using PHP you should create a file .php
and set in it your connection to the database.
Ex:
<?php
define("HOST", "nomedohost"); #Para o host com o qual você quer se conectar.
define("USER", "nomedousuario"); #O nome de usuário para o banco de dados.
define("PASSWORD", "senha"); #A senha do banco de dados.
define("DATABASE", "bancodedados"); #O nome do banco de dados.
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
?>
And then call him when you need to connect to the database.
To use a file PHP, the file you will call should be .php
Ex: index.php
And in it you must request your file .php
with the database, let’s imagine that file you created is called db.php
.
As I see you already know SQL
, I’ll give you an example using the Mysql
.
Let’s imagine that your table is like this:
Nome da tabela: users
Colunas: username, profile
username: Foo
profile: é um cara legal.
PHP file with your HTML
<?php
require_once('db.php');
$username = "Foo";
$sql = "SELECT * FROM `users` WHERE `username` = '$username'"; #sua query sql, um exemplo o SELECT *
$query_exec = $mysqli->query($sql); #Executa o comando select.
$row = $query_exec->num_rows; #Número de resultados encontrados.
$get = $query_exec->fetch_array(); #Cria um vetor associativo com os dados.
if($row > 0) {
#encontrou resultados.
$usuario = $get['username'];
$perfil = $get['profile'];
echo "{$usuario} {$perfil}"; #Pode fazer um echo de um html, ex: echo '<div id="profile">'.$perfil.'</div>';
#O resultado do echo seria: Foo é um cara legal.
} else {
#não encontrou nada.
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!--Colocando as tags PHP para exibir o echo no HTML-->
<div id="username"> <?php echo $usuario; ?> </div>
</body>
</html>
There are many ways you can manipulate the echo
of PHP, can do using AJAX, AJAX+Json, the web language ends up being very extensive, but as you need to learn to use the database, you can start doing some PHP course, and if you have no knowledge in programming, take a programming logic course.
You will need some programming language to do this. I believe it is simpler and the one that most suits you is the [tag:php].
– Francisco