Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* parte 1 */
- public function OpenConnection(){
- $connection = mysqli_connect(Database::_HOST, Database::_DB_USER, Database::_DB_PASSWORD, Database::_DB);
- mysqli_set_charset($connection,"utf8");
- if(!$connection){
- echo "<p font color=\"red\">Erro: Não foi possível conectar com o banco de dados." . PHP_EOL . "</p>";
- echo "<p font color=\"red\">Erro: " . mysqli_connect_errno() . PHP_EOL . "</p>";
- echo "<p font color=\"red\">Erro: " . mysqli_connect_error() . PHP_EOL . "</p>";
- }
- return $connection;
- }//DBOpenConnection's end
- /* parte 2 */
- $connection = Database::getInstance()->OpenConnection();
- $sql = "select * from user where user_name = ? and password = ?;";
- $statement = $connection->prepare($sql);
- //if any error happen in connection
- if (!$statement) {
- echo 'erro na consulta: '. $connection->errno .' - '. $connection->error;
- }
- //associate the user name and password with sql parameters,
- //execute the query and store the result
- $statement->bind_param('ss', $userName,$password);
- $statement->execute();
- $result = $statement->get_result();
- $user;
- //create and set the user variable
- while($row = mysqli_fetch_array($result)){
- $user = new User($row["idUser"], $row["name"], $row["email"], $row["user_name"], $row["password"], $row["type"], $row["active"], $row["idAdministrator"]);
- }
- echo "teste: ".$user->name;
- //close statement and connection
- $statement->close();
- Database::getInstance()->CloseConnection($connection);
- return $user; //aqui ta retornando nulo...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement