Jump to content

PDO connection + Funções


rexmage
 Share

Recommended Posts

Estava aqui eu a tentar fazer uma connection com PDO, quando me deparo com o seguinte erro:

----- > Fatal error: Call to a member function prepare() on a non-object in

Então o que eu fiz foi:

// Função que vai a uma classe e faz uma função com variaveis que eu passo:

public function externConnect($hostname, $username, $password, $database)
{
try {
$this->pdo = new PDO("firebird:dbname=".$database.";host=".$hostname."", $username, $password);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $err) {
die($err->getMessage());
}
}

$db->externConnect($hostname, $username, $password, $database);

Depois se eu correr isto assim:

$queryConfig = $db->pdo->prepare("SELECT * FROM EMPRESA");
$queryConfig->execute();
$config = $queryConfig->fetchObject();

Funca sem problemas... no entanto.. eu gostaria de usar classes entao pensei nisto:

class dados_empresa extends database(){

function teste($teste){

$queryConfig = $db->pdo->prepare("SELECT * FROM EMPRESA");
$queryConfig->execute();
$config = $queryConfig->fetchObject();

return $config->NOME;
}

}

Sei que estou a fazer algo errado, precisava perceber é, o que me falta? 🙂

Edited by yoda

<?PHP echo "Bo0m"; ?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.