Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:44:55+00:00 2026-06-12T11:44:55+00:00

I have this script which uses PHP PDO to access the MySQL database, but

  • 0

I have this script which uses PHP PDO to access the MySQL database, but the problem is my hosting provider has disabled PHP PDO, so now I’m stuck and have no idea how to change this code to access the database without PHP PDO:

<?php

    class DbHandler {

        private $dbname = '**********';
        private $host = '**********';
        private $user = '**********';
        private $pass = '**********';
        public $dbh;
        private $sth;

        public function __construct()
        {
            try{
                $this->dbh = new PDO("mysql:$this->host=localhost;dbname=$this->dbname", $this->user, $this->pass);
            }
            catch(PDOException $e){
                echo 'Unable to connect to database!';
            }
        }

        // Retrive all replays from the database
        public function selectAll($offset, $rowsperpage){

            $this->sth = $this->dbh->query("SELECT game_id, game_title,game_date_upload,game_file_name FROM games ORDER BY game_id DESC LIMIT $offset, $rowsperpage");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $replays = $this->sth->fetchAll();

            return $replays;
        }

        // Return number of replays from db
        public function numOfReplays(){
            $this->sth = $this->dbh->query("SELECT game_id FROM games");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $replays = $this->sth->fetchAll();
            $numOfReplays = count($replays);
            return $numOfReplays;
        }

        // Search db
        public function search1($search_text, $offset, $rowsperpage){
            $this->sth = $this->dbh->query("SELECT game_id, game_title,game_date_upload,game_file_name FROM games WHERE game_title LIKE '%$search_text%' ORDER BY game_id DESC LIMIT $offset, $rowsperpage");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $replays = $this->sth->fetchAll();
            return $replays;
        }

        public function search($search_text, $offset, $rowsperpage){
            $search_text = '%' . $search_text . '%';
            $this->sth=$this->dbh->prepare("SELECT game_id, game_title,game_date_upload,game_file_name FROM games WHERE game_title LIKE ? ORDER BY game_id DESC LIMIT $offset, $rowsperpage");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $this->sth->execute(array($search_text));
            $replays = $this->sth->fetchAll();
            return $replays;
        }

        public function numOfSearchResults($search_text){
            $search_text = '%' . $search_text . '%';
            $this->sth = $this->dbh->prepare("SELECT game_id FROM games WHERE game_title LIKE ?");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $this->sth->execute(array($search_text));
            $replays = $this->sth->fetchAll();
            $numOfReplays = count($replays);
            return $numOfReplays;
        }

        // Retrieve last five uploaded replays
        public function latestReplays(){
            $this->sth = $this->dbh->query("SELECT game_title,game_file_name FROM games ORDER BY game_date_upload DESC LIMIT 2");
            $this->sth->setFetchMode(PDO::FETCH_ASSOC);
            $lastReplays = $this->sth->fetchAll();

            return $lastReplays;
        }

        // Insert replay data in db
        public function exec($data=array())
        {
            $this->sth = $this->dbh->prepare("INSERT INTO games(game_title,game_description,game_file_name) values(?,?,?)");
            $this->sth->execute($data);
        }
    }
?>

My database works fine as I have used this MySQL test script to connect to it and it works:

<?php
    mysql_connect("myhost.com", "username", "password") or die(mysql_error());
    echo "Connected to MySQL<br/>";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:44:57+00:00Added an answer on June 12, 2026 at 11:44 am

    As JvdBerg says, you can switch hosts or change to MySQLi

    Here is a quick change from PDO to MySQLi

    From

    $this->dbh = new PDO("mysql:$this->host=localhost;dbname=$this->dbname", $this->user, $this->pass);`
    

    to

    $this->dbh = new mysqli($this->host,$this->user,$this->pass,$this->dbname);
    

    And

    from

    $this->sth = $this->dbh->query("SELECT game_id, game_title,game_date_upload,game_file_name FROM games ORDER BY game_id DESC LIMIT $offset, $rowsperpage");
    $this->sth->setFetchMode(PDO::FETCH_ASSOC);
    $replays = $this->sth->fetchAll();
    

    to

    $this->sth = $this->dbh->query("SELECT game_id, game_title,game_date_upload,game_file_name FROM games ORDER BY game_id DESC LIMIT $offset, $rowsperpage");
    $replays = $this->sth->fetch_all(MYSQLI_ASSOC);
    

    Rinse, lather, repeat for the rest of the class methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP search suggestion script which uses a MySQL database as its'
I have a php script which uses this below when a user uploads a
I have this part of script from my GAE application which uses webapp2, which
I have this PHP script which i'm grabbing images from a directory and displaying
I have a script which similar to this: foo.php class Foo { function Foo()
Right now, I have a script which uses PHP's tokenizer to look for certain
I have put together this little script which uses a list of words to
I have a jQuery text box autocomplete script which uses a PHP script to
I have this code, which uses ob_start php function. Which basically puts the echoed
I have a script which uses __autoload() to load classes (stupid, I know, this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.