Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]problem z update w bazie
shtoc
post
Post #1





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 18.11.2008
Skąd: Polska

Ostrzeżenie: (10%)
X----


mam taki kod
  1. <?PHP
  2. $pdo = new PDO('mysql:host=localhost;dbname=wrzuta', 'admin', 'xxx');
  3. $pdo -> query ('SET NAMES utf8');
  4. $sql = "select * from filmy where key is null limit 1";
  5. $statement = $pdo->query($sql);
  6.  
  7. $row = $statement->fetch(PDO::FETCH_ASSOC);
  8. unset($statement);
  9.  
  10. $adres=$row['web'];
  11. #$adres ='http://daria24.wrzuta.pl/film/wdKctZmPkJ/';
  12.  
  13. $url = curl_init($adres);
  14. curl_setopt($url, CURLOPT_USERAGENT, 'holmes/3.10.1 (OnetSzukaj/5.0; +http://szukaj.onet.pl)');
  15. curl_setopt($url, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($url, CURLOPT_CONNECTTIMEOUT, 5);
  17. curl_setopt($url, CURLOPT_HEADER, 0);
  18. $strona=curl_exec($url);
  19. #curl_close($url);
  20.  
  21. $DOM = new DOMDocument();
  22. @$DOM->LoadHTML(iconv("ISO-8859-2","UTF-8",$strona));
  23. $tablica = array();  #deklaracja tablicy
  24.  
  25. foreach ($DOM->getElementsByTagName('input') as $input)
  26. {
  27.    $id = $input->getAttribute('id');
  28.    if($id == 'new_cmnt_key')
  29.    {
  30.        $key = $input->getAttribute('value');
  31.    }
  32.  
  33. }
  34.  
  35. foreach ($DOM->getElementsByTagName('input') as $input)
  36. {
  37.    $id = $input->getAttribute('id');
  38.    if($id == 'link_do_pliku')
  39.    {
  40.        $web = $input->getAttribute('value');
  41.        #$web = str_replace('"http://', 'www.', $webe->nodeValue);
  42.  
  43.    }
  44.  
  45. }
  46. #var_dump($web);
  47. #exit;
  48. foreach ($DOM->getElementsByTagName('input') as $input)
  49. {
  50.    $id = $input->getAttribute('id');
  51.    if($id == 'miniatura_embed')
  52.    {
  53.        $object = $input->getAttribute('value');
  54.    }
  55.  
  56. }
  57. foreach ($DOM->getElementsByTagName('title') as $title)
  58. {
  59.    $tytul = str_replace('Wrzuta.pl - ', '', $title->nodeValue);
  60. }
  61.  
  62.  
  63. foreach ($DOM->getElementsByTagName('meta') as $meta)
  64. {
  65.    $tag = $meta->getAttribute('name');
  66.    if($tag == 'keywords')
  67.    {
  68.        $tagi = $meta->getAttribute('content');
  69.    }
  70. }
  71.  
  72.  
  73.    $sql = "INSERT INTO filmy(`tytul`, `tag`, `url`, `web`, `created_at`) VALUES(:tytul, :tag, :url, :web, :created_at)";
  74.    $statement = $pdo->prepare($sql);
  75.    $statement->bindValue(':tytul', $tytul, PDO::PARAM_STR);
  76.    $statement->bindValue(':tag', $tagi, PDO::PARAM_STR);
  77.     $statement->bindValue(':url', $object, PDO::PARAM_STR);
  78.    $statement->bindValue(':web', $web, PDO::PARAM_STR);
  79.   # $statement->bindValue(':key', $key, PDO::PARAM_STR);
  80.    $statement->bindValue(':created_at', date( 'Y-m-d H:i:s', time()), PDO::PARAM_STR);
  81.    $statement->execute();
  82.    var_dump($statement->errorInfo());
  83.  
  84.  
  85. $sql = "update filmy set key = :key where id = :id";
  86. $statement = $pdo->prepare($sql);
  87. $statement->bindValue(':key', $key, PDO::PARAM_STR);
  88. $statement->bindValue(':id', $row['id'], PDO::PARAM_INT);
  89. $statement->execute();
  90. ?>



i do tego baze :
id INT unsigned notnull auto_increment
tytul text notnull
tag text notnull
url text notnull
web text notnull
key text null
created_at datatime notnull

do bazy mam wrzucone 3 rekordy w ktorych podane jest :
id tytul url web created_at

i idea kodu jest pobranie 1 filmiku z bazy ktory nie ma uzupelnionego key
pobranie jego adresu i z adresu pobranie jego key i wpisanie go do bazy.

ale nie dziala siedze nad tym caly dzien i lipa:/
dostaje blad

Fatal error: Call to a member function fetch() on a non-object in C:\Program Files\WebServ\httpd\pobieranie4.php on line 7

prosze pomozcie jak ktos wie gdzie jest blad??
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 22.08.2025 - 19:37