Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i made database in phpmyadmin but when i use mysqli_connect to connect in database it doesn't work
(Unknown database)

this is function

PHP
function connect()
{
  $con=mysqli_connect("localhost","root","","insan");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }else{
      echo "Yes";
      return $con;
  }
}


why ?
Posted

1 solution

hi Heba
try this out


PHP
$DSN ="localhost " // hostname
$User="root"    // the username
$Password="password" // your password come in the 
$ conx = mysqli_connect($DSN,$User,$Password); 

// check if connection works

if (mysqli_connect errno())
{
   echo "failed to connect to mysql".mysqli_connect_errno();
}else
  echo "connected :)" ;

?>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900