PHP Warning: mysqli_query() expects at least 2 par

2019-03-07 08:37发布

问题:

First off, let me say hello, and thanks to all who have helped me find answers for the past year or so, just by looking up my questions. I have a problem now that has been driving me crazy fro the past 2 days. I have looked up previous answers, tried variations, and am still stuck.

Anyhow, I'm modding a bit of code to take input from a DB table instead of a CSV file. I first get an error saying 'cannot find file', this is my DB connect file (proven to work in all other scripts that use it). It is in the same dir as the file executing, and permissions on the debian system are 755 for all. I have moved the connect code into the StoreUpload.php file. The original code called out to a functions file to execute the mysqli_query, and I got the 'expects 2, got 1' error. I moved the queries into the StoreUpload file. I am still getting the 'expects 2, got 1' error on the first query from the original code (my input works fine, same DB). I am out of ideas, it's probably something simple, but I can't see it. Here are some code snippets. output screen shot:

SELECT
  p.products_id as v_products_id,
  p.products_model as v_products_model,
  p.products_sku as v_products_sku,
  p.products_upc as v_products_upc,
  p.products_image as v_products_image,
  p.products_price as v_products_price,
  p.products_weight as v_products_weight,
  p.products_date_added as v_date_added,
  p.products_date_available as v_date_avail,
  p.products_tax_class_id as v_tax_class_id,
  p.products_quantity as v_products_quantity,
  p.manufacturers_id as v_manufacturers_id,
  subc.categories_id as v_categories_id FROM
  `zc_products` as p,
  `zc_categories` as subc,
  `zc_products_to_categories` as ptoc
WHERE
  p.products_id = 'ptoc.products_id' AND
  p.products_model = 'EPPIRFA-9V' AND
  ptoc.categories_id = 'subc.categories_id'

PHP Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/mark/development/epStoreUpload.php on line 375

and the code:

$sql = "SELECT
    p.products_id as v_products_id,
    p.products_model as v_products_model,
    p.products_sku as v_products_sku,
    p.products_upc as v_products_upc,
    p.products_image as v_products_image,
    p.products_price as v_products_price,
    p.products_weight as v_products_weight,
    p.products_date_added as v_date_added,
    p.products_date_available as v_date_avail,
    p.products_tax_class_id as v_tax_class_id,
    p.products_quantity as v_products_quantity,
    p.manufacturers_id as v_manufacturers_id,
    subc.categories_id as v_categories_id".
    $custom_filelayout_sql.
    " FROM
    `zc_products` as p,
    `zc_categories` as subc,
    `zc_products_to_categories` as ptoc
    WHERE
    p.products_id = 'ptoc.products_id' AND
    p.products_model = '$items[1]' AND
    ptoc.categories_id = 'subc.categories_id'
    ";
    echo $sql;
$result = mysqli_query($dbc,$sql) or trigger_error("Query Failed! SQL: $dbc - 

Error: ".mysqli_error(), E_USER_ERROR); $result = mysqli_query($sql);

The SELECT query works directly in PHPMyAdmin.

回答1:

I think this will help

mysqli_query($con,$sql);

It has two parameters one is connection and other is SQL query



回答2:

ARRRGH! I had 2 mysqli_query statements in there, the second which had only 1 param. I had been reading the code for so long, I kept reading what I THOUGHT was there, and not what was. Found it after I stepped away for a bit. Thanks for looking, anyway.



标签: php mysqli