Hi everyone
I am trying to use my function that is the database connection on an ajax page.
See the next code and if can help me will be great
Thanks community
config.php
functions.phpPHP Code:<?php
require_once 'functions.php';
?>
ajax.phpPHP Code:<?php
class User {
/* Variables */
public $MySqlUserName = 'root';
public $MySqlPassword = 'something';
public $Con;
public function DatabaseConnection() {
$TryConnection = new PDO('mysql:host=localhost;dbname=something', $this->MySqlUserName,$this->MySqlPassword, array(PDO::ATTR_PERSISTENT => true));
if ($TryConnection) {
$this->Con = $TryConnection;
}
else {
// Redirect
}
return $this->Con;
}
}
?>
PHP Code:<?php
require 'config.php';
$SQL = $this->Con->prepare("the query");----> this query is what is not working it is because of the ($this->Con), i tried to add on the top of this file:
$UserClass = new User();
$UserClass = DatabaseConnection();
but it still not working, anyone can help me? Thanks Community
?>
index.php
PHP Code:<?php
require_once 'config.php';
$UserClass = new User();
$UserClass->DatabaseConnection();
?>



Reply With Quote
Bookmarks