php - receive returned value by class in oop -
i have class :
<?php class connection { public $db; public function __construct() { $this->db = new mysqli('localhost', 'root', '', ''); if($this->db->connect_errno > 0){ die('error ' . $this->db->connect_error); } $this->db->set_charset("utf8"); } } class masssave extends connection { public $sql; public function insert_all { // works if ( $sql = $this->db->query("insert $db_name ($str_db_value) values ($str_form_value_found) ")) { return true; } else { return false; } } } ?>
in masssave
class seted $sql
public , want use class in pages , register page
$save = new masssave; if ( $save->sql = true ) { echo 'ok'; } else { echo 'failed'; }
but upper code not working , echo 'ok'
query failed ,
i use if ( $save->sql == true )
code echo 'failed'
i newbie in oop , think php classes ok , think doing wrong way checking returned value
- replace
$sql = $this->db->query
$this->sql = $this->db->query
--$sql
- local variable.$this->sql
- object property - call proper method after
$save = new masssave;
use$save->insert_all()
- use comparison (but not assigment)
$save->sql = true
- assigment,$save->sql == true
- comparison. assigment reutrns value of variable,$save->sql = true
true.
Comments
Post a Comment