/* Verbindungsdatei */Wie Datenbank mit mvc in PHP verbinden
class dbconnect{
public function connect(){
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'demo';
$connection = mysqli_connect($host,$user,$pass,$db);
return $connection;
}
}
/* dao Datei */
include 'dbconnect.php';
class dao extends dbconnect{
private $conn;
function __dao(){
$dbcon = new dbconnect();
$conn = $dbcon->connect();
}
function select($table , $where='' , $other=''){
if(!$where = ''){
$where = 'where' . $where;
}
$sele = mysqli_query($this->conn,"SELECT * FROM $table $where $other") or die(mysqli_error($this->conn));
echo $sele;
return $sele;
}
}
/* controler file */
include 'dao.php';
$d = new dao();
if(isset($_POST['btn_login'])){
extract($_POST);
$username = $_POST['user_name'];
$pswd = $_POST['pswd'];
$sel = $d->select("users" , "email_id = '" . $username . "'AND password='" . $pswd . "'") or die('error from here');
$result = mysqli_fetch_array($sel) ;
if($result['email_id'] == $username && $result['password'] == $pswd){
SESSION_START();
$_SESSION['user_name'] = $result['email_id'];
$_SESSION['message'] = 'Invalid Username Or Password';
header("location:index.php");
}
else{
$_SESSION['error'] = 'Invalid Username Or Password';
// header("Location:login.php");
}
}
Ich habe einen Fehler Warnung: mysqli_query() erwartet Parameter 1 ist mysqli, null gegeben in /opt/lampp/htdocs/ankit_demo/dao.php on line 13
Warnung: mysqli_error() erwartet Parameter 1 als mysqli, null in/opt/lampp/htdocs/ankit_demo /dao.php auf l in 13
wie löst man das? Bitte helfen Sie mir, dies zu lösen.
'$ this-> conn' ==' $ conn' – Rizier123
Hauptproblem ist, dass Sie in Ihrem Konstruktor keine Klasseneigenschaft '$ conn' erstellen, sondern nur eine lokale Variable. Außerdem sollten Sie '__construct()' verwenden, nicht php4-style Konstruktoren (eigentlich eine seltsame Mischung) –
dann wie kann ich das lösen? Bitte sagen Sie mir, ich bin ein neuer Entwickler in PHP –