I put the website into aws cloud and the website is written in php. When using the command
$conn = mysqli_connect($server, $user, $pass, $database);
the page does not work. How do we use$conn = new mysqlit($server, $user, $pass, $database);
the website works, but it does not connect to the base any longer. Is there any difference in these commands?
CodePudding user response:
The purpose of these commands is the same, but they are two very different approaches to the same goal. Whereas mysqli_connect is procedural, 'new mysqli' is creating an object.
In practice, this means that mysqli_connect can be used with other procedural commands (such as mysqli_query). The OOP way of doing it, with an object, is now the preferred method but does force you to use the object to communicate with the database.
Object oriented (OOP):
$conn = new Mysqli($server, $user, $pass, $database);
$result = $conn->query("SELECT * FROM somewhere");
Procedural:
$conn = mysqli_connect($server, $user, $pass, $database);
$result = mysqli_query($conn,"SELECT * FROM somewhere");
However, I would strongly advise to use the object oriented way for a more future proof application. (I believe that the procedural method is actually deprecated.)
More info and examples can be found here: https://www.php.net/manual/en/mysqli.query.php
CodePudding user response:
be sure that the password and username is the same as the one in the aws cloud