-3
I’m still beginner in php, here’s the code, here’s giving syntax error
<?php
function conexao(){
$banco = "curosphp_mysql";
$usuario = "root";
$senha = "";
$host = "localhost";
mysqli_select_db($conn, $banco);
}
conexao();
?>
Update:
<?php
function conexao(){
$banco = "curosphp_mysql";
$usuario = "root";
$senha = "";
$host = "localhost";
$conn = mysqli_connect($host, $usuario, $senha, $banco);
mysqli_select_db($conn, $banco);
}
conexao();
?>
$conn
does not exist in the scope of the function and another future problem ... its function does not return value (the connection in particular).– rray
Well, the variable
$conn
, that inmysqli_select_db
does not exist, so yes, there is the error.– Woss
$Conn = mysqli_connect($host, $user, $password, $bank);
– Sarah Leesy
this code solves the problem?
– Sarah Leesy
Now you are giving the error giving you an unexpected } please help me
– Sarah Leesy
How is your code?
– adventistaam
<?php Function connected(){ $bank = "curosphp_mysql"; $user = "root"; $password = ""; $host = "localhost"; $Conn = mysqli_connect($host, $user, $password, $bank); mysqli_select_db($Conn, $bank); } connected(); ?>
– Sarah Leesy
The documentation has complete examples of how to do, both procedural and OOP: http://php.net/manual/en/book.mysqli.php - documentation is made for this very thing, to read, to learn, to study, and more specific doubts that escape the basic use of Apis bring here to the site, see example of procedural connection explained in doc: http://php.net/manual/en/mysqli.construct.php#example-1784
– Guilherme Nascimento