Class conexão e diferença de var/array
Olá imasterianos :joia: , estou com um problema para adicionar uma nova conexão MYSQL a uma class pois sempre que que adiciono uma nova fica aparecendo que não foi possível conectar ao bd, e outra é que não entende foi no config.php tem os valores para conexão do bd em array e na class a var-array não existe tipo ao invés de ser o array está uma var com o memso nome do array porem simplificado com wnderlines, vou por eles ai para ver se alguém pode me ajudar.
functon.php
include_once 'classes.php';
$mysql = new QueryClass($CONFIG_rag_serv, $CONFIG_rag_user, $CONFIG_rag_pass, $CONFIG_rag_db, $CONFIG_cp_serv, $CONFIG_cp_user, $CONFIG_cp_pass, $CONFIG_cp_db);
function htmlformat($string) {
$resp = "";
for ($i = 0; isset($string[$i]) && ord($string[$i]) > 0; $i++)
$resp .= "".ord($string[$i]).";";
return $resp;
}
function moneyformat($string) {
$string = trim($string);
$return = "";
$len = strlen($string) - 1;
for ($i = 0; $i < strlen($string); $i++) {
if ($i > 0 && $i % 3 == 0)
$return = ",".$return;
$return = $string[$len - $i].$return;
}
return $return;
}
function inject($string) {$permitido = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.@$&-_/§*°ºª"; //dicionario de palavras permitidas
for ($i=0; $i<strlen($string); $i++) {
if (strpos($permitido, substr($string, $i, 1)) === FALSE) return TRUE;
}
return FALSE;
}
//etc.
class.php
class ResultClass {
var $result;
var $row;
function ResultClass($arg1) {
$this->row = FALSE;
$this->result = $arg1;
}
function fetch_row() {
if ($this->result !== TRUE && $this->result !== FALSE)
$this->row = mysqli_fetch_row($this->result);
else
$this->row = FALSE;
return $this->row;
}
function count() {
if ($this->result)
return mysqli_num_rows($this->result);
return 0;
}
function row($pos) {
if (isset($this->row[$pos]))
return $this->row[$pos];
return FALSE;
}
function free() {
if (empty($this->result))
return;
if ($this->result !== TRUE && $this->result !== FALSE)
mysqli_free_result($this->result);
}
}
class QueryClass {
var $rag_link;
var $cp_link;
var $notice_link;
var $result;
function QueryClass($rag_addr, $rag_username, $rag_password, $rag_db, $cp_addr, $cp_username, $cp_password, $cp_db, " $notice_addr, $notice_username, $notice_password, $notice_db ") {
global $lang;
$this->rag_link = mysqli_connect($rag_addr,$rag_username,$rag_password,$rag_db) or die($lang['DB_ERROR']);
$this->cp_link = mysqli_connect($cp_addr,$cp_username,$cp_password,$cp_db) or die($lang['DB_ERROR']);
" $this->notice_link = mysqli_connect($notice_addr,$notice_username,$notice_password,$notice_db) or die($lang['DB_ERROR']); "
}
function Query($query, $table = 0) {
global $lang;
if ($table)
$this->result = mysqli_query($this->cp_link, $query);
else
$this->result = mysqli_query($this->rag_link, $query);
if (strpos($query,"SELECT") === 0)
return new ResultClass($this->result);
if ($this->result === FALSE)
return FALSE;
return TRUE;
}
function finish() {
if (empty($this->result))
return;
if ($this->result !== TRUE && $this->result !== FALSE)
mysqli_free_result($this->result);
}
}
Em QueryClass eu destaquei com aspas duplas onde eu editei (adicionei valores a mais)
config.php
//sql connections
$CONFIG['rag_serv'] = 'localhost';
$CONFIG['rag_user'] = 'root';
$CONFIG['rag_pass'] = 'vertrigo';
$CONFIG['rag_db'] = 'ragnarok';
$CONFIG['log_db'] = 'ragnarok';
$CONFIG['cp_serv'] = 'localhost';
$CONFIG['cp_user'] = 'root';
$CONFIG['cp_pass'] = 'vertrigo';
$CONFIG['cp_db'] = 'cp';
$CONFIG['notice_serv'] = 'localhost';
$CONFIG['notice_user'] = 'root';
$CONFIG['notice_pass'] = 'vertrigo';
$CONFIG['notice_db'] = 'notice';
Após isso como eu não entendi muito isso aqui:
$CONFIG['valor1'] = 'valor2';
Tipo não teria que criar um $var=array() ? alguém poderia me explicar por favor?
Desde já grato, muito complicado :ermm:
Discussão (4)
Carregando comentários...