when i am calling the function connect and closeDb inside showAll there is an error.
class DBConnect {
private $con;
private function connect() {
$con = mysql_connect("localhost", "root", "");
mysql_select_db('school');
}
private function closeDb() {
mysql_close($this->con);
}
public function showAll() {
self::connect();
echo "THis is from the showAll method";
self::closeDb();
}
}
Mysql extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
Learn basics of object oriented programming: http://php.net/manual/en/language.oop5.php
This Line looks false. $con = mysql_connect("localhost", "root", "");
If think you want to do $this->con = mysql_connect("localhost", "root", "");
Then
public function showAll() { $this->connect(); echo "THis is from the showAll method"; $this->closeDb(); }
public function showAll() { $this->connect(); echo "THis is from the showAll method"; $this->closeDb(); }
use $this !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.