anubisgfx Posted May 25, 2009 Share Posted May 25, 2009 Hello! I've tried solving this problem for days, I'm kinda like a noob at OOP PHP, so I'd like to get some help. When i run this code: Class library class mysql_connector{ private $hostname = "127.0.0.1"; private $username = "root"; private $password = "ur mom"; private $db = "sjosiden"; private $con; public function connect(){ $this->con = mysql_connect($this->hostname,$this->username,$this->password) or die(mysql_error()); if (!$this->con){ echo "Kunne ikke koble til mySQL-Databasen.<br />" . mysql_error(); exit; } mysql_select_db($this->db, $this->con); if (!mysql_select_db($this->db)){ echo "Kunne ikke velge applikasjonsdatabasen.<br />" . mysql_error(); } } public function disconnect(){ mysql_close($this->con); } } class pdata_retriever{ // Requires an mysql_connector object. private $query; private $query_result; private $func_selector; public $output; public function get_pdata($func_selector){ $this->query = "SELECT '$this->func_selector' FROM pdata"; $this->query_result = mysql_query($this->query); if (!$this->query_result){ echo "Kunne ikke gjøre SQL-Spørring:" . mysql_error(); exit; } if (mysql_num_rows($this->query_result) == 0){ echo "Raden er tom. GG."; exit; } $this->output = mysql_fetch_array($this->query_result, MYSQL_NUM); echo $this->output[0]; } } View page <?php require("class_lib.php"); $mysql = new mysql_connector(); $mysql->connect(); $pdata = new pdata_retriever(); echo $pdata->get_pdata("project_title"); ?> The problem: I've got all kinds of errors, but with my current code, nothing happens! The data is in my mySQL database, which is by the way running on an XAMPP installation on Mac OS X 10.5.7. If anyone could help me out, it would really kick some motivation back in my learning of PHP. Thanks! Link to comment https://forums.phpfreaks.com/topic/159583-stuck-on-some-basic-mysql-oop-stuff/ Share on other sites More sharing options...
Ken2k7 Posted May 25, 2009 Share Posted May 25, 2009 In your pdata_retriever class, method get_pdata, $this->func_selector is not only undefined, but you also messed up the variable interpolation and the quotes. $this->query = "SELECT '$this->func_selector' FROM pdata"; Link to comment https://forums.phpfreaks.com/topic/159583-stuck-on-some-basic-mysql-oop-stuff/#findComment-841954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.