www.webdeveloper.com
Results 1 to 4 of 4

Thread: mysql_query() expects parameter 2 to be resource, object given in...

  1. #1
    Join Date
    Feb 2014
    Posts
    22

    mysql_query() expects parameter 2 to be resource, object given in...

    Warning: mysql_query() expects parameter 2 to be resource, object given in C:\xampp\htdocs\search.php on line 15

    I get this error message whenever I try to

    This is my code

    <?php

    $db = 'htdocs\as4.mdb';

    $conn = new COM('ADODB.Connection');

    $search = $_POST['search'];

    $sql = "SELECT * FROM vendor WHERE vendorName like '%search%' OR
    address like '%search%' or
    city like '%search%' or
    provState like '%search%' or
    country like '%search%'";

    $result = mysql_query($sql, $db) or die (mysql_error());

    $number = mysql_num_rows($result);
    // <h3>$number of results found search for "$search"</h3>

    while($row = mysql_fetch_array($result))
    {
    $vendorName = $row['vendorName'];
    $address = $row['address'];
    $city = $row['city'];
    $provState = $row['provState'];
    $country = $row['country'];
    }


    ?>

    It maybe something small, but at the moment I can't seem to figure out what it is. Any help?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    You start out the script using COM to make an ADODB connection, but then try to use MySQL functions to do a database query. If it's a MySQL database, then you would use mysql_connect() to connect to it. If you want/need to use a COM object, then you would use COM functions to query it, but mixing the two is probably not ever going to work.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2014
    Posts
    22
    Ok I see. I'm trying to search the query, but I want to use it with the COMM function what can I do to make that happen? The example I have was one of the many ways I saw online except for the COMM part which I added in to connect the database.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    I've never used the COM stuff, so don't really know my way around it. Example #2 on this page shows some possibly useful stuff.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles