A
A
Atype2018-03-08 13:22:31
PHP
Atype, 2018-03-08 13:22:31

Why is it impossible to connect to the database through the function?

I can't connect to the database through a function.
Here is that function:

function connect()
{
  $dbc = mysqli_connect('localhost','root','','lesson');
  return $dbc;
}

When you output this function. And you check for the existence of the $dbc variable, it turns out that this variable does not exist.
If you connect directly like this, then everything works:
$dbc = mysqli_connect('localhost','root','','lesson');

It seems to me that the error is in the function.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-03-08
@Twedis

The scope of the $dbc variable is limited to the connect() function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question