简体   繁体   English

根据另一个表的第一个值使用PDO查询MYSQL数据库

[英]Query MYSQL database using PDO based on the first value of another table

Hi I am having trouble querying a mysql table based on the first value of another table here is my code. 嗨,我在根据另一个表的第一个值查询mysql表时遇到了问题,这是我的代码。

<?php

$host    = 'localhost';
$db      = 'msdds';
$user    = 'root';
$pass    = '';
$charset = 'utf8';



$dsn = "mysql:host=$host;dbname=$db;charset=$charset";



$opt = [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_EMULATE_PREPARES   => false,
        ];


$dbh = new PDO($dsn, $user, $pass, $opt);



$sql  = $dbh->query("SELECT name FROM employee WHERE remarks != 'done' and branch ='EGYPT' and tenure=""");
$rows = $sql->fetchAll();
echo json_encode($rows);



?>

I want to add a query on tenure based on the first value of another table. 我想基于另一个表的第一个值在权属上添加查询。 I need to query from another table currently it is connected to employee table but I have another table that contains tenure and based on the first value there will be the content of tenure 我需要从另一个表中查询,当前它已连接到employee表,但是我还有另一个包含任期的表,根据第一个值,将有任期的内容

Replace your Query with this 以此替换您的查询

$sql = $dbh->query("SELECT name FROM employee WHERE remarks != 'done' AND (branch ='EGYPT' and tenure='')"); $ sql = $ dbh-> query(“从雇员的名字中选择备注!='done'AND(branch ='EGYPT'and tenure =')”);

$rows = $sql->fetchAll(); $ rows = $ sql-> fetchAll();

tenure is also equal to single quote. 任期也等于单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM