-2

This is my MySQL query:

SELECT 
`idmaster`,`book_id`, `title`,  `choseStatus`, `choseStatus2`, `choseStatusMarker`, `choseStatusSpecial`, `choseStatus3`,`classifybyoclc_calln_lcc`, `classifybyoclc_calln_nlm`, `classifybyoclc_calln_ddc`,  `choseStatus4`, `choseStatus5`, `choseStatus6`, `choseStatus7`,  `classifybyoclc_fast`
FROM
`RU_test`.`a_sg1libunique`
WHERE 
(
(`title` LIKE '%method%')
AND
(`code` = 'QD')
)
AND `choseStatusMarker` = "U"
AND `book_id` IS NOT NULL
ORDER BY `code`, CAST(EXTRACTNUMBER(`classifybyoclc_calln_lcc`) AS UNSIGNED) , `classifybyoclc_calln_lcc`,`classifybyoclc_calln_nlm`,`title`
LIMIT 0,500

This works perfectly on PHPMyAdmin.

But when I use PHP:

    $dsn = 'mysql:host=localhost;port:8889';
        $user = 'root';
        $password = 'root';
        try {
        $pdo = new PDO($dsn, $user, $password);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    echo "came here";
    $qstring = <<<EOT
SELECT 
`idmaster`,`book_id`, `title`,  `choseStatus`, `choseStatus2`, `choseStatusMarker`, `choseStatusSpecial`, `choseStatus3`,`classifybyoclc_calln_lcc`, `classifybyoclc_calln_nlm`, `classifybyoclc_calln_ddc`,  `choseStatus4`, `choseStatus5`, `choseStatus6`, `choseStatus7`,  `classifybyoclc_fast`
FROM
`RU_test`.`a_sg1libunique`
WHERE 
(
(`title` LIKE '%method%')
AND
(`code` = 'QD')
)
AND `choseStatusMarker` = "U"
AND `book_id` IS NOT NULL
ORDER BY `code`, CAST(EXTRACTNUMBER(`classifybyoclc_calln_lcc`) AS UNSIGNED) , `classifybyoclc_calln_lcc`,`classifybyoclc_calln_nlm`,`title`
LIMIT 0,500
EOT;
    $stmt = $pdo->query($qstring);
    var_dump($stmt);
    var_dump($pdo->errorInfo());

$stmt returns false.

And $pdo->errorInfo() returns:

array (3) [
    0 => string (5) "3D000"
    1 => integer 1046
    2 => string (20) "No database selected"
]

But I have already prefixed a_sg1libunique with RU_test.

Strangely, if $qstring is another query:

$qstring = "SELECT DISTINCT `choseStatus2` FROM `RU_test`.`a_sg1libunique` WHERE `choseStatus2` NOT LIKE '%:%'";

There's no issue at all. The query gets executed successfully.

Why is this so, and how may I solve this?

forgodsakehold
  • 870
  • 10
  • 26

0 Answers0