-1
How do I connect to another database using the connection I already have and works perfectly in another database?
When I change only the connection name appears:
Notice: Undefined variable: conn2 in C: Program Files (x86) Easyphp-5.3.6.0 www store funcao conecta2.php on line 22
Here’s the code:
<?php
function conecta2( ){
  if(!defined("HOST")){
     define('HOST','localhost');
  }
  if(!defined("BD")){
     define('BD','cadastro');
  }
  if(!defined("USER")){
     define('USER','root');
  }
  if(!defined("PASS")){
     define('PASS','');
  }
try {
$conn2 = new PDO('mysql:host='.HOST.';dbname='.BD.'', ''.USER.'', ''.PASS.'');
$conn2->exec("SET NAMES 'utf8'");
}
catch(PDOException $erro){
echo $erro->getMessage();
}
return $conn2; // esta é a linha 22
}
						
It worked! Thank you
– Clayton Campos
@Claytoncampos knows to mark the answer as right?
– Filipe Moraes