tecmeister Posted June 8, 2010 Share Posted June 8, 2010 Hi Guys, I only get this Warning when I use it in a class. This is the class script: require_once("_class/delete.php"); $delete = new delete($ID); class database { function __construct(){ $this->connect(); } public function connect(){ mysql_connect("localhost","**********","**********")or die("<h1>Connect ERROR</h1>".mysql_error()); mysql_select_db("**********")or die("<h1>MYSQL SELECT ERROR</h1>".mysql_error()); } public function query($sql) { return $query = mysql_query($sql)or die("<h1> MYSQL QUERY ERROR </h1>".mysql_error()); } public function fetch($query) { return $fetch = mysql_fetch_assoc($query) } } class delete extends database { function __construct($ID) { $sql = "SELECT path FROM news WHERE ID='$ID' LIMIT 1"; $query = $this->query($sql); $fetch = $this->fetch($query); $this->delImage($fetch['path']); exit(); } function delImage($image) { unlink($image); } } This is the not class working code $sql = "SELECT path FROM news WHERE ID='$ID' LIMIT 1"; $query = mysql_query($sql)or die("<h1> MYSQL QUERY ERROR </h1>".mysql_error()); $fetch = mysql_fetch_assoc($query); $image = $fetch['path']; unlink($image); Please could someone tell me it happens in a class. Thanks for your help, tecmeister. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2010 Share Posted June 8, 2010 Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. And you should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON so that php will both report and display all the errors it detects. You would have seen that the mysql connection was not being made. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069718 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 Even if I remove the __constructor and have it as a basic method I still get the same Warning. I have got the: error_reporting(-1); ini_set('display_error', 1); The thing that I dont understand it that it has know problem not in a class but when in a class it gives me th same Warning. I have the __constructor connecting to the database at the start of the page. Much appreciated for your help, tecmeister. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069815 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069822 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 Its - ini_set('display_errors', 1); And if you do what the quote out of the php.net documentation tells you to ADD, your code works. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069823 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 require_once("_class/delete.php"); $delete = new delete($ID); class database { function __construct(){ $this->connect(); } public function connect(){ mysql_connect("localhost","**********","**********")or die("<h1>Connect ERROR</h1>".mysql_error()); mysql_select_db("**********")or die("<h1>MYSQL SELECT ERROR</h1>".mysql_error()); } public function query($sql) { return $query = mysql_query($sql)or die("<h1> MYSQL QUERY ERROR </h1>".mysql_error()); } public function fetch($query) { return $fetch = mysql_fetch_assoc($query) } } class delete extends database { function selectDB($ID) { $sql = "SELECT path FROM news WHERE ID='$ID'"; $query = $this->query($sql); $fetch = $this->fetch($query); $this->delImage($fetch['path']); exit(); } function delImage($image) { unlink($image); } } I have put the exit() in so I can see the Warning. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069825 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 I typed it corret on the site. it was just a miss type on here. And if you do what the quote out of the php.net documentation tells you to ADD, your code works I have no idea what this means please can you tell me. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069826 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2010 Share Posted June 9, 2010 You are not calling your selectDB() method, so it would be a little hard for your code to work. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069827 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 You are not calling your selectDB() method, so it would be a little hard for your code to work. Yeah I am, I just missed copying and pasting it on the site. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069828 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 You are not calling your selectDB() method, so it would be a little hard for your code to work. Yeah I am, I just missed copying and pasting it on the site. If your not going to post your actual code we can't help. Were not here to play guess. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069836 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 This is the database class that I use to connect to the database. On the index page I refer to the database class. class database { function __construct(){ $this->connect(); } public function connect(){ mysql_connect("localhost","nurevol1_teci","b748a9766483850584695e364c8b2d34")or die("<h1>Connect ERROR</h1>".mysql_error()); mysql_select_db("nurevol1_pyung")or die("<h1>MYSQL SELECT ERROR</h1>".mysql_error()); } public function query($sql) { return $query = mysql_query($sql)or die("<h1> MYSQL QUERY ERROR </h1>".mysql_error()); } public function fetch($query) { return $fetch = mysql_fetch_assoc($query); } } This is the class that I'm using to delete te Image. class delete extends database { function selectDB($ID) { $sql = "SELECT path FROM news WHERE ID='$ID'"; $query = parent::query($sql); $fetch = parent::fetch($query); $this->delImage($fetch['path']); exit(); } function delImage($image) { unlink($image); } } This is the code that I use to get the get the class and refer to it. // GETTING THE ID FROM THE URL $ID = $_GET['id']; $page = $_GET['delete']; if((isset($_GET['delete'])) && ($_GET['delete'] == 'news')) { require_once("_class/delete.php"); $delete = new delete(); $delete->selectDB($ID); } O and just to note that I have just put the parent:: into try new stuff. I was using $this-> Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069841 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 Again, you are not calling the parents __construct(). Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069843 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 AGAIN, yes I do. On the index page I run the __constructor(), and the page that I'm running the delete class on is displayed on the index as require_once("/pages/delete.php"). Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069846 Share on other sites More sharing options...
trq Posted June 9, 2010 Share Posted June 9, 2010 AGAIN, yes I do. Where? You don't. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069861 Share on other sites More sharing options...
tecmeister Posted June 9, 2010 Author Share Posted June 9, 2010 AGAIN, yes I do. Where? You don't. If I copy and paste everything we will be here for ever. And if I put in the delete method parent::__construct() as the first thing i still get the same warning. Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069869 Share on other sites More sharing options...
syed Posted June 9, 2010 Share Posted June 9, 2010 tecmeister what is the warining? Quote Link to comment https://forums.phpfreaks.com/topic/204239-class-warning-mysql_fetch_assoc/#findComment-1069870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.