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

3
  • I think you should enable cURL in PHP, see this question: stackoverflow.com/questions/1347146/… Also: use mysqli or PDO Commented Dec 3, 2014 at 21:05
  • Actually I enabled it but getting same result Commented Dec 3, 2014 at 21:08
  • You need to fetch your SQL query result.. Now you are just passing a resource. Not the value Commented Dec 3, 2014 at 21:42

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Yes I did this but still have the warnings and error
if you did, please edit your question to show what code you were running. We can only debug code that we can see.
This is correct. OP is not fetching the data from the query result. At this moment it's just a resource

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.