2
<?php
    $con=mysql_connect("localhost","root","");
    mysql_select_db("google",$con);

    $sql="SELECT urlname FROM url WHERE id=12";
    $url=mysql_query($sql);
    $result = get_web_page( $url );

    if ( $result['errno'] != 0 ) {
        echo "errror";
    }

    if ( $result['errmsg'] != 200 ) {
        echo "error";
    }

    $page = $result['content'];
    while ($row = mysql_fetch_array($page)) {
        printf($row[0]);  
    }

    function get_web_page( $url1 )
    {
        $options = array(
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_USERAGENT      => "spider", // who am i
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
            CURLOPT_TIMEOUT        => 120,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        );

        $ch = curl_init( $url1 );
        // create a new cURL resource
        //$ch    = curl_init();

        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL,$url1);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch );
        curl_close( $ch );

        $header['errno']   = $err;
        $header['errmsg']  = $errmsg;
        $header['content'] = $content;
        return $header;
    }
?>                      

Here is my php code and when I echo $page I am getting following warning and error as well as did not getting any data from the requested url.

Warnings:

Warning: curl_init() expects parameter 1 to be string, resource given in C:\xampp\htdocs\CSE391\curl.php on line 36

Warning: curl_setopt_array(): supplied argument is not a valid cURL handle resource in C:\xampp\htdocs\CSE391\curl.php on line 37

Warning: curl_exec() expects parameter 1 to be resource, null given in C:\xampp\htdocs\CSE391\curl.php on line 38

Warning: curl_errno() expects parameter 1 to be resource, null given in C:\xampp\htdocs\CSE391\curl.php on line 39

Warning: curl_error() expects parameter 1 to be resource, null given in C:\xampp\htdocs\CSE391\curl.php on line 40

Warning: curl_getinfo() expects parameter 1 to be resource, null given in C:\xampp\htdocs\CSE391\curl.php on line 41

Warning: curl_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\CSE391\curl.php on line 42 error

zajonc
  • 1,935
  • 5
  • 20
  • 25
Abu Sufian
  • 991
  • 1
  • 6
  • 15

1 Answers1

1

mysql_query returns a resultset object, not results data. you need to eg fetch_array() from the resultset object each result row; that result row will have the url

see http://php.net/manual/en/function.mysql-fetch-array.php

Andras
  • 2,995
  • 11
  • 17