Skip to main content

Posts

Showing posts from February 17, 2022

PHP#26MySQL#22 - Hướng đối tượng Phần 3+4

//lib.php <?php class tintuc{ private $link; //chứa mã kết nối //kết nối: function connect($host, $user, $pass, $db) { $this->link=@mysqli_connect($host,$user,$pass) or die("Không thể kết nối đến Server!"); mysqli_select_db($this->link,$db) or die("Không tồn tại DB này!"); mysqli_query($this->link,"set names 'utf8'"); } //Xây dựng hàm query: function query($sl) { $kq=mysqli_query($this->link,$sl) or die(mysqli_error()); return $kq; } //Xây dựng hàm fetch: function fetch($kq) { $d=mysqli_fetch_array($kq); return $d; } //Hàm num_rows: function num_rows($kq) { return mysqli_num_rows($kq); } //Hàm thể loại:Lấy các thể loại theo ngôn ngữ và trạng thái: function theloai($lang="vi", $anhien=1) { $sltl="select * from theloai where (lang='$lang' or '$lang'='') and (AnHien=$anhien or $anhien=-1) order by ThuTu ASC"; $k...