Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:27:49+00:00 2026-06-15T19:27:49+00:00

I am constructing an API with Javascript and for security reasons I switched my

  • 0

I am constructing an API with Javascript and for security reasons I switched my PHP database calls over to PDO.

Since doing so, I have had troubles with queries returning empty arrays (NOTE: not MySQL syntax errors). The latest example is this:

/*JAVASCRIPT*/
var getSampleEntity = function(params) {
//Returns Object
return $.ajax({ 
    url: URL + 'downloadQuadrat_Organism.php',
    type: 'POST',
    data: { 'organismID': params.oid, 'quadratID': params.qid },
    dataType: dataType
});
}

Header data sent from browser:

/*PACKAGE HEADER INFO*/
Request URL:http://..../downloadQuadrat_Organism.php
Request Method:POST
Status Code:200 OK
...
Form Data:
organismID:3

Which is sent to server…

/*PHP*/
//Init
$resultset = array();
$quadratID = $_POST['quadratID'];
$organismID = $_POST['organismID'];
$sql = 'SELECT * FROM Quadrat_Organism WHERE organismID = :organismID OR WHERE quadratID = :quadratID';

//Main
try{
    $db = connect();
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':quadratID', $quadratID);
    $stmt->bindParam(':organismID', $organismID);
    $stmt->execute();

    while($row = $stmt->fetch(PDO::FETCH_ASSOC))
        $resultset[] = $row;

    //Return result in JSON
    $resultset = json_encode($resultset);
    print_r($resultset);

} catch(PDOException $e){
    print 'Error!: '.$e->getMessage().'<br/>';
}//End try catch

$db = null;

I expect an array of results in JSON (dummy-data in database should return 5 results), instead I receive [] (empty JSON array).

I believe the issue is at the PHP level, but I cannot identify the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:27:51+00:00Added an answer on June 15, 2026 at 7:27 pm

    you have an error in your where Condition MySQL query:

    Try this out, use this

    $sql = 'SELECT * FROM Quadrat_Organism 
    WHERE organismID = :organismID OR quadratID = :quadratID';
    

    instead of:

    $sql = 'SELECT * FROM Quadrat_Organism 
    WHERE organismID = :organismID OR WHERE quadratID = :quadratID';
    

    use only one where in your queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use an API which sends a fax. I have a PHP
I'm constructing an ecommerce application in Symfony, and I have a page which lists
I'm constructing a JFileFilter on a JFileChooser, however an error occurs where I have
When constructing an API response, which method is better for (manually) returning the status
I have a list of items I want to feed to an API via
I have a list of FB ids, is there a canon way of constructing
I am importing JSON data from a public database URI http://data.seattle.gov/api/views/3k2p-39jp/rows.json and the rows
I wrote a simple regex for my application's API: ^api/([^/]+)/([^/.]+)\.([^$/?=&]+)(?:\?(.*))?$ this becomes /app/api/$1.php?action=$2&format=$3&$4 In
Suppose I have an API that returns a Task as an object: private static
I have such GUI situation: Window1>vbox1>vbox2>scrolledvindow1>treeview1>treestore1. Program takes data from database through MySql C-api.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.