This is MySQLi extension. I have two tables, sources
and source_categories
. In sources
there is a column that stores the source category id, it is called, source_category_id
as a foreign key. In the source_categories
table, source_category_id
is the primary key and source_category_name
holds the actual category names. Pretty basic.
I want to INNER JOIN
both tables on source_category_id
. I've worked with INNER JOIN
before with success. However, I am getting Fatal error: Call to a member function bind_param() on a non-object
when I go to test the page.
The prepared statement has only one placeholder as you'll see below, it is fed from a variable which contains a query string value.
This doesn't work:
$sql = 'SELECT source_category_id, source_by, source_name, source_contact, source_category_name
FROM sources INNER JOIN source_categories
ON sources.source_category_id = source_categories.source_category_id
WHERE source_type = ?
ORDER BY source_name ASC';
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $ps);
$stmt->bind_result($source_category_id, $source_by, $source_name, $source_contact, $source_category_name);
$stmt->execute();
$stmt->store_result();
$numRows = $stmt->num_rows;
However, omitting the INNER JOIN
code along with source_category_name
and $source_category_name
from their respective places like so:
$sql = 'SELECT source_category_id, source_by, source_name, source_contact
FROM sources
WHERE source_type = ?
ORDER BY source_name ASC';
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $ps);
$stmt->bind_result($source_category_id, $source_by, $source_name, $source_contact);
$stmt->execute();
$stmt->store_result();
$numRows = $stmt->num_rows;
works just fine, but I want the category names too.
I'm obviously missing something really stupid or I'm righteously violating syntax somewhere, but my tired eyes and hurting brain can't find the problem(s).
Any help would be greatly appreciated. Thank you!