How do I connect to another database using the connection I already have and work 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 \ function \ online2.php 22
Here is 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
}