PHP connection using phpMyAdmin

Asked

Viewed 1,140 times

-1

Good evening, I’m doing a college job of creating an e-commerce site, but I’m not able to connect with my comic book, can anyone help me ? When I turn I keep saying you’re wrong on line 17, but I couldn’t fix it, thank you ! ! ! !

inserir a descrição da imagem aqui

  • ( ! ) 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

  • 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

  • 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

1 answer

0


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.

  • 4

    When DB is Mysql, PDO is inferior to Mysqli in all aspects and Mysqli is not being discontinued. Unfortunately for the great emphasis on wrong information in the answer o -1 is inevitable, but I am open to review if the problems are adjusted.

  • 1

    I was able to make a lot of progress at work! ! Thank you very much, now only xD appearance is missing

  • @Bacco, no doubt it was a mistake of mine to say that mysqli was being discontinued, I did not pay attention during the review. Of course mysqli when it comes to Mysql is superior, it is specific to this database, but I always indicate the use of PDO, and always use PDO. Thank you so much for the ear tug! Community grows like this! <3

  • @Bado I thank, and I apologize for the little mistake about mysqli, in addition, any doubt knows that can count on gnt, we will always do our best to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.