I need a urgent help…i got some code from online…but i am not able to understand mysql which is already deprecated. I want to convert this code into mysqli with oops concepts.please help me…
here is code:
<?php
define("DBHOST","localhost");
define("DBUSER","root");
define("DBPWD","");
define("DB","prabbhas");
class DB_FUNCTIONS {
public function __construct() {
$conn = mysql_connect(DBHOST,DBUSER,DBPWD);
$db_select = mysql_select_db(DB,$conn);
}
public function getResults($table)
{
$data = array();
$query = mysql_query("SELECT * FROM $table") or die(mysql_error());
$num_rows = mysql_num_rows($query);
if($num_rows>0) {
while($row=mysql_fetch_assoc($query))
$data[]=$row;
}
return $data;
}
public function allProducts()
{
$query = mysql_query("SELECT * FROM wallpapers");
while($row=mysql_fetch_assoc($query))
$data[]=$row;
return $data;
}
public function getproductPhoto($id)
{
$photo = mysql_result(mysql_query("SELECT pic FROM wallpapers where id = $id"),0);
return $photo;
}
}
?>
I’m happy to offer suggestions to code changes that you make and post as far as I am able, but sorry, I’m not going to just do the conversion for you. Have a read up on mysqli and PDO from the links provided and give it a go.