hello, im new to OOP in PHP and i got problem in PHPMysql since mysql migrated to improved mysql. I really need your ideas since i got a problem to connect a database using OOP and the same time, i want also to use Object-Oriented Mysqli in querying my database.
This is my DB.class.php:
<?php
$DB_SERVER = 'localhost';
$DB_USERNAME = 'username';
$DB_PASSWORD = 'password';
$DB_DATABASE = 'database';
class DB
{
function __construct()
{
$conn= new mysqli($DB_SERVER, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE) or
die('Oops connection error -> ' . $conn->error());
$conn->select_db($DB_DATABASE)
or die('Database error -> ' .$conn->error());
}
}
?>
Here is my User.class.php:
<?php
include_once 'DB.class.php';
class User
{
//Database connect
public function __construct()
{
$db = new DB();
}
//Registration process
public function register_user($name, $username, $password, $email)
{
$password = md5($password);
$sql = mysql_query("SELECT uid from users WHERE username = '$username' or email = '$email'");
$no_rows = mysql_num_rows($sql);
if ($no_rows == 0)
{
$result = mysql_query("INSERT INTO users(username, password, name, email) values ('$username', '$password','$name','$email')") or die(mysql_error());
return $result;
}
else
{
return FALSE;
}
}
my question is, is there possible if using the following code inside my User class ($conn->query) since i try to use oop in mysqli?
$conn->query("SELECT uid from users WHERE username = '$username' or email = '$email'");
Thank you.