-3
Good people I am a little behind in things and so far I could not learn php7 again.
Well these files(3) there that I am showing you is the way I do to show database record in a show way. I wonder if there is a way to create an updated version of these codes.
Or if there is something more current and easier to be implementing in my projects.
conection.php
<?php
class xDatabase{
var $DB_HOSTNAME = "localhost";
var $DB_USERNAME = "user";
var $DB_PASSWORD = "";
var $DB_DATABASE = "Xbanco";
var $DB_CONNECTION = false;
var $DB_RESULT = false;
var $DB_RESULT_ROWS = 0;
var $DB_AFFECTED_ROWS = 0;
var $DB_PREV_INSERT_ID = 0;
function xDatabase() {
$this->DB_CONNECTION = @mysql_connect($this->DB_HOSTNAME, $this->DB_USERNAME, $this->DB_PASSWORD);
if (!$this->DB_CONNECTION);
if (!@mysql_select_db($this->DB_DATABASE));
}
function query($query) {
if (!$this->DB_CONNECTION)
return false;
if (!$this->DB_RESULT = @mysql_query($query, $this->DB_CONNECTION))
return false;
switch(strtoupper(substr($query, 0, 6))){
case "SELECT" : $this->DB_RESULT_ROWS = @mysql_num_rows($this->DB_RESULT);
while ($db_result = mysql_fetch_array($this->DB_RESULT, MYSQL_ASSOC))
{
$db_data[] = $db_result;
}
if (is_array($db_data))
{
return $db_data;
}
else
return false;
break;
case "INSERT" : $this->DB_AFFECTED_ROWS = @mysql_affected_rows($this->DB_RESULT);
$this->DB_PREV_INSERT_ID = @mysql_insert_id();
break;
case "DELETE" : $this->DB_AFFECTED_ROWS = @mysql_affected_rows($this->DB_RESULT);
break;
case "UPDATE" : $this->DB_AFFECTED_ROWS = @mysql_affected_rows($this->DB_RESULT);
break;
}
return true;
}
function querySingle($query)
{
if (!$db_result = $this->query($query))
return false;
return $db_result[0];
}
function clean()
{
if ((!$this->DB_CONNECTION) || (!$this->DB_RESULT))
return false;
if (!(@mysql_free_result($this->DB_RESULT)))
return false;
$this->DB_RESULT = false;
$this->DB_RESULT_ROWS = 0;
$this->DB_AFFECTED_ROWS = 0;
$this->DB_PREV_INSERT_ID = 0;
return true;
}
function close()
{
if (!$this->DB_CONNECTION)
return false;
if (@mysql_close($this->DB_CONNECTION))
{
$this->DB_RESULT = false;
$this->DB_CONNECTION = false;
$this->DB_RESULT_ROWS = 0;
$this->DB_PREV_INSERT_ID = 0;
return true;
}
return false;
}
}
?>
class.exibir.php
<?php
class Exibir
{
var $DB_RESULT_ROWS = 0;
########## Empresa ############
function Sobre(){
$db = new xDataBase();
$strSql = "SELECT * FROM `tb_sobre` WHERE id = 1";
$result = $db->query($strSql);
$this->DB_RESULT_ROWS = $db->DB_RESULT_ROWS;
$db->close();
if($this->DB_RESULT_ROWS != 0){
return($result);
}else{
return false;
}
}
}
?>
sobre.php
<?php $B = $Exibir->Sobre(); if(is_array($B)){ foreach($B as $b) { ?>
<?php echo utf($b['Texto']); ?>
<?php } } // Fecha Foreach
else{ echo "Falha ao exibir resultados do banco de dados!!!";} // Fecha Else
?>
Well I believe my problem was not about connection in Pdo but rather about a class file with functions that connect to a different table!
– PoneiMlditoUM