define ('DenSul', 1); Include ('DB.php'); Include ('function.php'); $db = new DB(); $densul = new DenSul(); $db->connect(); $densul->header($namesite, $template_css); $densul->sql();
Выдает ошибку:
Notice: Undefined variable: DB in T:\home\localhost\blog\source\function.php on line 47
Fatal error: Call to a member function query() on a non-object in T:\home\localhost\blog\source\function.php on line 47
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Актуальные контакты:
Telegram: @Nikker_web
E-Mail: tarasevich.email@gmail.com
Портфолио https://www.behance.net/d4d4186e
Разрабатываю дизайн групп в соц сетях, сайтов, приложений, другой дизайн под заказ
Актуальные контакты:
Telegram: @Nikker_web
E-Mail: tarasevich.email@gmail.com
Разрабатываю дизайн групп в соц сетях, сайтов, приложений, другой дизайн под заказ
Портфолио https://www.behance.net/d4d4186e
Question
AMD
Добрый день форумчани.
Помогите пожалуста разобратся с ООП на php.
Я мало что еще понимаю в нем, но все же.
Суть проблемы такова:
Есть 3 файла(function.php, db.php, index.php);
В db.php написан класс DB, в котором написаны функции(их тут куча, скрипт не совсем мой) типа:
function query($query) {
$this->q_id = mysql_query($query, $this->db_connect_id);
if (! $this->q_id ) {
$error1 = mysql_error();
$error2 .= mysql_errno();
die ("ОШИБКА: Ошибка базы.<br> Не возможно выполнить SQL запрос: $query <br>Вид ошибки: $error1 <br>Ошибка SQL: $error2");
exit;
}
$this->query_count++;
return $this->q_id;
}
function fetch_row($q_id = "") {
if ($q_id == "") {
$q_id = $this->q_id;
}
$result = mysql_fetch_array($q_id, MYSQL_ASSOC);
return $result;
}
А в function.php написан класс densul в котором я к примеру написал функцию
function sql() {$query = $DB->query("select * from ds_news");
while( $row = $DB->fetch_row($query) ) {
$amd = $row['id'];
echo "$amd";
}
}
Страница index.php
define ('DenSul', 1);Include ('DB.php');
Include ('function.php');
$db = new DB();
$densul = new DenSul();
$db->connect();
$densul->header($namesite, $template_css);
$densul->sql();
Выдает ошибку:
Notice: Undefined variable: DB in T:\home\localhost\blog\source\function.php on line 47
Fatal error: Call to a member function query() on a non-object in T:\home\localhost\blog\source\function.php on line 47
Как мне записать класс DB в функцию sql ?
Link to comment
Share on other sites
5 answers to this question
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.
Note: Your post will require moderator approval before it will be visible.