mysql - Connecting to Database Using PHP OOP -


i developing php oop application, need with. developing class(fetch_assoc) has function db_connect. connects database. have getrows() function extracts rows database , returns it. here code:

function __construct() {        mysql_connect("localhost","root","") or die(mysql_error());        mysql_select_db("testproject") or die(mysql_error());   }       function getrows() {        $sql = "select * record";        $this->arr2 = $this->querystring($sql);        //declaring $return array        $return = array();        foreach ($this->arr2 $key=>$value) {              $return[$key] = $value;        }//foreach ends here        return $return;   }       function querystring($sql) {        $query =  mysql_query($sql);        $row = mysql_fetch_assoc($query);        return $row;   }// function querystring ends here()   

then on other page, use below code fetch out objects returned , display it... dont understand whats going wrong!

$class = new fetch_assoc;   $results = $class->getrows();   //echo out   foreach ($results $result) {       foreach ($result $key=>$value) {       echo "hello";    echo $key . ": " . $value;   }//foreach ($result $key=>$value) ends here   

$this->host = $db_config['host'];

where complete localhost @ $this->host or $db_config['host']


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -