Preciso conectar em 3 banco de dados, como ficaria o script abaixo ?
<?php ob_start(); header("Content-Type: text/html; charset=ISO-8859-1", true);
class DB {
private $server;
private $db;
private $user;
private $pass;
public $conexao;
public $baseurl;
function __construct() {
$this->server="localhost";
$this->db="teste";
$this->user="root";
$this->pass="";
$this->Conectar();
}
function Conectar(){
$this->conexao=mysql_connect($this->server,$this->user,$this->pass) or die('Erro ao se conectar');
mysql_select_db($this->db,$this->conexao) or die('Erro ao selecionar a DB');
}
function PesquisaTabela($tabela){
return mysql_query("Select * from $tabela");
}
function PesquisaCampos($campos, $tabela){
return mysql_query("Select $campos from $tabela");
}
function PesquisaUnica($tabela,$id="0"){
//echo "Select * from $tabela where id=$id";
return(mysql_fetch_array(mysql_query("Select * from $tabela where id=$id")));
}
function ExecutaQuery($query){
return mysql_query($query);
}
function Nlinhas($query){
return mysql_num_rows($query);
}
function ListarCampos($tabela)
{
$result = mysql_query("SHOW COLUMNS FROM ".$tabela);
$field = "";
while($resultado=mysql_fetch_array($result)) {
//print_r($resultado);
foreach($resultado as $campo=>$valor){
if($campo=='0')
$field.=$valor.",";
}
}
return $field;
}
}
?>
Pergunta
Paulo Campos 01
Preciso conectar em 3 banco de dados, como ficaria o script abaixo ?
<?php ob_start(); header("Content-Type: text/html; charset=ISO-8859-1", true); class DB { private $server; private $db; private $user; private $pass; public $conexao; public $baseurl; function __construct() { $this->server="localhost"; $this->db="teste"; $this->user="root"; $this->pass=""; $this->Conectar(); } function Conectar(){ $this->conexao=mysql_connect($this->server,$this->user,$this->pass) or die('Erro ao se conectar'); mysql_select_db($this->db,$this->conexao) or die('Erro ao selecionar a DB'); } function PesquisaTabela($tabela){ return mysql_query("Select * from $tabela"); } function PesquisaCampos($campos, $tabela){ return mysql_query("Select $campos from $tabela"); } function PesquisaUnica($tabela,$id="0"){ //echo "Select * from $tabela where id=$id"; return(mysql_fetch_array(mysql_query("Select * from $tabela where id=$id"))); } function ExecutaQuery($query){ return mysql_query($query); } function Nlinhas($query){ return mysql_num_rows($query); } function ListarCampos($tabela) { $result = mysql_query("SHOW COLUMNS FROM ".$tabela); $field = ""; while($resultado=mysql_fetch_array($result)) { //print_r($resultado); foreach($resultado as $campo=>$valor){ if($campo=='0') $field.=$valor.","; } } return $field; } } ?>Ajuda ai galera :/
Editado por Paulo Campos 01Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.