Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access MYSQL database without using PHP PDO?
    primarykey
    data
    text
    <p>I have this script which uses php pdo to access the mysql database but the problem is my hosting provider have disable php pdo so now i'm stuck and have no idea how to change this code to access the database without php pdo:</p> <pre><code>&lt;?php class DbHandler { private $dbname='**********'; private $host='**********'; private $user='**********'; private $pass='**********'; public $dbh; private $sth; public function __construct() { try{ $this-&gt;dbh = new PDO("mysql:$this-&gt;host=localhost;dbname=$this-&gt;dbname", $this-&gt;user, $this-&gt;pass); } catch(PDOException $e){ echo 'Unable to connect to database!'; } } //retrive all replays from db public function selectAll($offset, $rowsperpage){ $this-&gt;sth=$this-&gt;dbh-&gt;query("SELECT game_id, game_title,game_date_upload,game_file_name FROM games ORDER BY game_id DESC LIMIT $offset, $rowsperpage"); $this-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $replays=$this-&gt;sth-&gt;fetchAll(); return $replays; } //return number of replays from db public function numOfReplays(){ $this-&gt;sth=$this-&gt;dbh-&gt;query("SELECT game_id FROM games"); $this-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $replays=$this-&gt;sth-&gt;fetchAll(); $numOfReplays=count($replays); return $numOfReplays; } //search db public function search1($search_text, $offset, $rowsperpage){ $this-&gt;sth=$this-&gt;dbh-&gt;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-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $replays=$this-&gt;sth-&gt;fetchAll(); return $replays; } public function search($search_text, $offset, $rowsperpage){ $search_text='%'.$search_text.'%'; $this-&gt;sth=$this-&gt;dbh-&gt;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-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $this-&gt;sth-&gt;execute(array($search_text)); $replays=$this-&gt;sth-&gt;fetchAll(); return $replays; } public function numOfSearchResults($search_text){ $search_text='%'.$search_text.'%'; $this-&gt;sth=$this-&gt;dbh-&gt;prepare("SELECT game_id FROM games WHERE game_title LIKE ?"); $this-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $this-&gt;sth-&gt;execute(array($search_text)); $replays=$this-&gt;sth-&gt;fetchAll(); $numOfReplays=count($replays); return $numOfReplays; } //retrive last five uploaded replays public function latestReplays(){ $this-&gt;sth=$this-&gt;dbh-&gt;query("SELECT game_title,game_file_name FROM games ORDER BY game_date_upload DESC LIMIT 2"); $this-&gt;sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $lastReplays=$this-&gt;sth-&gt;fetchAll(); return $lastReplays; } //insert replay data in db public function exec($data=array()) { $this-&gt;sth=$this-&gt;dbh-&gt;prepare("INSERT INTO games(game_title,game_description,game_file_name) values(?,?,?)"); $this-&gt;sth-&gt;execute($data); } } ?&gt; </code></pre> <p>My database works fine as i have used this mysql test script to connect to it and it works:</p> <pre><code>&lt;?php mysql_connect("myhost.com", "username", "password") or die(mysql_error()); echo "Connected to MySQL&lt;br /&gt;"; ?&gt; </code></pre> <p>I'm still a newbie in php and this is abit too advance for me, hope someone can help. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload