www.webdeveloper.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    12

    PHP5 OOP and ajax - database connection

    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
    PHP Code:
    <?php
    require_once 'functions.php';
    ?>
    functions.php
    PHP 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;
            
        }
    }
    ?>
    ajax.php
    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 workinganyone can help meThanks Community
    ?>

    index.php
    PHP Code:
    <?php
     
    require_once 'config.php';
     
    $UserClass = new User();
     
    $UserClass->DatabaseConnection();
    ?>

  2. #2
    Join Date
    Apr 2010
    Posts
    223
    I wish i could help but:
    a. your code seems really convoluted
    b. its missing parts of its code anyway.

    How can help tell what you've left out accidently apart from whats not there on purpose?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



Recent Articles