Сделал два простых класса один состоит из стандартных функций пхп для работы с базой данных, другой наследует от этого класса. В производном классе запускаю родительский конструктор и выскакивает ошибка Конструктор родительский. Код (Text): function __construct ($hostname="",$user="",$password="",$db=""){ $this->link_id= mysql_connect($hostname,$user,$password); if(!$this->link_id && $db!="") { $this->show_error("Error connect Mysql or wrong table name."); }else{ if(!mysql_select_db($db, $this->link_id)) echo"error"; } }
Хм, во-первых пароля нет как такового по умолчанию, а во-вторых если конструктор запустить из самого родителя, с теми же настройками, то все работает. Где же проблема?
Пардон Класс родительский Код (Text): <? class db{ private $link_id; private $query_id; function __construct ($hostname="",$user="",$password="",$db=""){ $this->link_id= mysql_connect($hostname,$user,$password); if(!$this->link_id && $db!="") { $this->show_error("Error connect Mysql or wrong table name."); }else{ if(!mysql_select_db($db, $this->link_id)) echo"error"; } } function query($string=""){ $this->query_id=mysql_query($string,$this->link_id); return $this->query_id; } function result_array($query_id=""){ if ( $query_id != "" ) $this->query_id=$query_id; $res=array(0); for($i=0;$i<$this->total_rows($this->query_id);$i++){ array_push($res ,mysql_fetch_assoc($this->query_id)); } return $res; } function result_object($query_id=""){ if ( $query_id != "" ) $this->query_id=$query_id; $res=array(0); for($i=0;$i<$this->total_rows($this->query_id);$i++){ array_push($res ,mysql_fetch_object($this->query_id)); } return $res; } function show_error($mes=""){ echo $mes; } function total_rows($query_id){ if ( $query_id != "" ) $this->query_id=$query_id; $total_rows=mysql_num_rows($this->query_id); return $total_rows; } function close(){ return mysql_close($this->link_id); } function retur_ins_id(){ return mysql_insert_id($this->link_id); } }?> Класс производный Код (Text): <?php class tree extends db{ function __construct(){ parent::__construct(); } function build_tree(){ } } ?> index файл Код (Text): <? include"db.class.php"; include"bufer.class.php"; include"parser.class.php"; include"tree.class.php"; $html= new buffer(); $tree= new tree("localhost","root","","test"); $data['editor']= "The world is mine"; $html->view("templates/index.tlp", $data); ?> Error Код (Text): Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in Z:\home\db\www\db.class.php on line 7 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in Z:\home\db\www\db.class.php on line 13
обана только сейчас понял Код (Text): function __construct($hostname="",$user="",$password="",$db=""){ parent::__construct($hostname,$user,$password,$db); Всем спасибо, как всегда ответ находишь сам после того как выложишь код на форуме