-1
Come on, first you need to take a look here at how to ask, avoid placing images with the code and yes put the same code.
Now I will exemplify the connections with the database.
The class PDO:
<?php
$dbname="nome do banco de dados";
$dbuser="usuário do banco de dados";
$dbpassword="senha de acesso ao banco de dados";
try{
$conn=new PDO('mysql:host=localhost;dbname='.$dbname,$dbuser,$dbpassword); #1
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); #2
}catch(PDOException $error){
return '<h3>Erro de conexão:</h3><p>'.$error->getMessage().'</p>';
}
?>
1 - Connections are established by creating instances of the PDO base class. No matter which driver you want to use; you always use the PDO class name. The constructor accepts parameters to specify the source of the database (known as the DSN) and optionally for the username and password (if any).
2 - In addition to defining the error code, the PDO will launch a Pdoexception and define its properties to reflect the error code and error information.
Complete documentation of the PDO class
I only use the PDO class for new projects, the use of mysql has been discontinued, so I suggest you start taking into account learn PDO, as it will facilitate the evolution of the systems you create, this is my opinion.
The Class mysqli:
<?php
$dbname="nome do banco de dados";
$dbuser="usuário do banco de dados";
$dbpassword="senha de acesso ao banco de dados";
$conn=new mysqli('localhost',$dbuser,$dbpassword,$dbname); #1
if (mysqli_connect_error()) {
die('Erro na conexão ('.mysqli_connect_errno().')'.mysqli_connect_error()); #2
}
$conn->close(); #3
?>
1 - Open the connection to the database.
2 - The function mysqli_connect_error, will return a string representing the last error that happened with the last call the function mysqli_connect(). If no error has occurred, this function will return an empty string.
3 - Close a previously opened connection to the database.
Complete documentation of the Mysqli class
The class mysqli is an improvement of mysql
The obsolete mysql:
<?php
$dbuser="usuário do banco de dados";
$dbpassword="senha de acesso ao banco de dados";
$conn=mysql_connect('localhost',$dbuser,$dbpassword); #1
if (!$conn) {
die('Erro na conexão: '.mysql_error()); #2
}
mysql_close(); #3
?>
1 - Open a connection to the Mysql server.
2 - mysql_error() returns the text of the previous Mysql operation error message.
3 - Close the Mysql connection.
Documentation of obsolete Mysql
Notice, this extension is deprecated since PHP 5.5.0 and has been removed in PHP 7.0.0!
I must point out that it is always good to read the documentation and functions that will be used in the project, always looking for the best form, a clean code and well commented to facilitate future maintenance, even if it is by other people.
Answering your question directly (!) Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\wamp64\www\Trabalho fabiano\login02.php on line 17 (!)
means that in its version of PHP
it has already been discontinued.
( ! ) Fatal error: Uncaught Error: Call to Undefined Function mysql_connect() in C: wamp64 www Work Fabiano login02.php on line 17 ( ! ) Error: Call to Undefined Function mysql_connect() in C: wamp64 www Work Fabiano login02.php on line 17
– Bado
I think mysql_connect() has been obsolete for a long time, according to the PHP manual mysqli_connect() -> https://www.php.net/manual/en/function.mysqli-connect.php
– brunox99x
Depending on the version of your PHP mysql_connect() does not work if I am not mistaken it was removed from PHP 7, I suggest you use PDO because mysql and mysqli are vulnerable to sql injection
– kervincandido