I have this class
class mysql {
public $dbname, $dbuser, $dbpass, $dbhost, $dbcon;
public $auto_slashes;
public $sql_error;
public $row_count;
public function __construct($dbn, $dbh, $dbu, $dbp) {
$this->dbhost=$dbh;
$this->dbname=$dbn;
$this->dbpass=$dbp;
$this->dbuser=$dbu;
$this->auto_slashes = true;
$this->doconnect();
}
public function doconnect()
{
$this->dbcon=mysql_connect($this->dbhost,$this->dbuser, $this->dbpass);
mysql_select_db($this->dbname);
}
but I'm getting this connection error, line 17 is the $this->dbcon=mysql_connect line:
<br />
<b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on '127.0.0.7' (60) in <b>/Users/jr/pear/share/pear/lib/db.class.php</b> on line <b>17</b><br />
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/Users/jr/pear/share/pear/lib/db.class.php</b> on line <b>55</b><br />
NULL
This is my php web page below:
Do you know why the error says 127.0.0.7 instead of 127.0.0.1? I am hiting the server remotely maybe that is why.
How can I fix the connection error. It creates the new $db object and it looks like it calls the constructor?
The database Server and web server are working before I changed it from procedural to object oriented.
TIA,
$dbhost="127.0.0.1:3306";
$dbuser="xxx";
$dbpass="xxxx";
$dbname="xxxx";
$db=new mysql($dbname, $dbhost, $dbuser, $dbpass);
require_once 'lib/global.inc.php';
$sql = 'SELECT todo,date,name FROM task WHERE todo > "" ';
if($db->get_row($sql)){
$result = $obj->get_row($sql,$type='MySQL_ASSOC');
while($result_of_result = mysql_fetch_assoc($result))
{
$arr_result[] = $result_of_result;
}
};