PHP使用内部连接准备语句中断

PHP使用内部连接准备语句中断,php,join,mysqli,inner-join,Php,Join,Mysqli,Inner Join,这是MySQLi扩展。我有两个表,sources和source\u categories。在sources中有一列存储源类别id,它被称为source\u category\u id,作为外键。在source\u categories表中,source\u categories\u id是主键,source\u categories\u name保存实际的类别名称。非常基本 我想内部连接源\u类别\u id上的两个表。我曾经成功地与内部连接一起工作过。但是,我遇到了致命错误:当我去测试页面时,调

这是MySQLi扩展。我有两个表,
sources
source\u categories
。在
sources
中有一列存储源类别id,它被称为
source\u category\u id
,作为外键。在
source\u categories
表中,
source\u categories\u id
是主键,
source\u categories\u name
保存实际的类别名称。非常基本

我想
内部连接
源\u类别\u id
上的两个表。我曾经成功地与
内部连接一起工作过。但是,我遇到了
致命错误:当我去测试页面时,调用非对象上的成员函数bind_param()

准备好的语句只有一个占位符,如下所示,它由一个包含查询字符串值的变量提供

这不起作用:

$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;
但是,将
内部联接
代码与
源类别名称
$source\u category\u名称
一起从各自的位置省略,如下所示:

$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;
很好,但我也想要类别名称

很明显,我遗漏了一些非常愚蠢的东西,或者我在某处违反了语法,但是我疲惫的眼睛和受伤的大脑找不到问题所在

任何帮助都将不胜感激。谢谢大家!

变化

$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';


@杰克击中了它的头,非常感谢你的帮助。以下是工作查询:

$sql = 'SELECT sources.source_category_id, sources.source_by, sources.source_name, sources.source_contact, source_categories.source_category_name
    FROM sources INNER JOIN source_categories
    ON sources.source_category_id = source_categories.source_category_id
    WHERE sources.source_type = ?
    ORDER BY sources.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;

再次感谢

我试过了,但还是有同样的错误,谢谢!你可能会从有太多关于@ShaunakShukla可能重复的解决方案中得到答案,我已经在SO和互联网上倾诉了几个小时,直到必要时才想发布。有趣的是,我读了你链接到的那个帖子。这没用。而且,这不是你提到的问题的重复。我想知道我的查询失败的原因,而不是错误的含义。谢谢你<代码>选择源。源\u类别\u id
,因为否则
源\u类别\u id
不明确。
$sql = 'SELECT sources.source_category_id, sources.source_by, sources.source_name, sources.source_contact, source_categories.source_category_name
    FROM sources INNER JOIN source_categories
    ON sources.source_category_id = source_categories.source_category_id
    WHERE sources.source_type = ?
    ORDER BY sources.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;