doula2426 2012-05-02 18:05
浏览 57
已采纳

为什么我无法访问我的数据库?

This my dbconnect.class.php

<?php 

class Connect
{
    //public $error;
    public $db;
    public function __construct()
    {
        $link = mysql_connect("localhost","root","1");
        $db = mysql_select_db("tarih",$link);
        $this->db = $db;
    }
}

$connect = new Connect();
$connect = $connect->db;
?>

And this is main php file (header.class.php)

<?php
require_once ('dbconnect.class.php');
class Header extends Connect
{ 
    public $headers = array();
    public function __construct() 
    { 
        /* 
        * Bu sınıf sayfaların header bilgilerini işler. 
        */  
    } 

    public function sayfaHeader($sayfa = true) 
    { 
        $sql = "SELECT * FROM header WHERE id='" . $sayfa . "'"; 
        $query = mysql_query($sql,$connect) or mysql_error(); 
        echo $sql;
    } 


} 

$header = new Header();
echo $header->sayfaHeader();
?>

But when i run this code I see this error:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\ilk\class\header.class.php on line 16

What is the problem?

  • 写回答

2条回答 默认 最新

  • doulan3966 2012-05-02 18:09
    关注

    Your $connect variable is a parent class. You need to point to the $link variable it contains.

    Change:

    $query = mysql_query($sql, $connect) or mysql_error(); 
    

    to

    $query = mysql_query($sql,$link) or mysql_error(); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改