Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z zapytanie mysql_db_query
lukasz_jaw
post 9.04.2012, 21:29:05
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 9.04.2012

Ostrzeżenie: (0%)
-----


Witam
Posiadam klase ktorej celem jest polaczenie z baza oraz wyswietlenie danych podane w zapytaniu zapytania:

Kod
<?php
class QueryIterator implements Iterator
{
    public $result;
    public $connection;
    public $data;
    public $key=0;
    public $valid;
    
    
    function __construct($host, $dbname, $user, $password)
    {
        $this->connection= mysql_connect($host,$user,$password);
        mysql_select_db($dbname);
        
        if($this->connection==false)
        {
            echo "nie polaczyl sie";
        }
    }
    
    public function exceute($query)
    {
        [b]$this->result= mysql_db_query($this->connection,$query);[/b]
        if((mysql_num_rows($this->result))>0)
            $this->next ();
    }
    
    public function rewind() {}
    
public function current() {
    return $this->data;
}

public function key() {
    return $this->key;
}

public function next() {
    if($this->data == mysqli_fetch_assoc($this->result))
    {
        $this->valid=true;
        $this->key+=1;
    }
else {
        $this->valid=false;    
    }
}

public function valid() {
    return $this->valid;
}

}
?>


Nastepnie w pliku index.php znajduje sie:
Kod
<?php
include_once 'db.connect.php';
$qi=new QueryIterator("localhost","booking", "lukasz", "admin123");
$qi->exceute("select email, username from users");
while ($qi->valid())
{
    print_r($qi->current());
    $qi->next();
}
?>


Po wykonaiu uruchomienu pliku wyskauje mi blad:
Kod
Warning: mysql_db_query() expects parameter 1 to be string, resource given in C:\wamp\www\PhpProject1\db.connect.php on line 24

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\wamp\www\PhpProject1\db.connect.php on line 25


Polaczenie dziala natomiast cos jest z zapytaniem, nie wiem czemu....
Dzieki
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 02:29