简体   繁体   中英

SQL Query won't return what is in the row (PHP)

My PHP:

<?php

function connectDB($user, $pass) {
    try {   
        return(new PDO("mysql:host=localhost;dbname=Test;", $user, $pass));
    } catch(PDOException $ex) {
        return $ex;
    }
}


$db = connectDB("root", "root");
    if ($db instanceof PDOException) {
        die($db->getMessage());
    }
$query = "SELECT * FROM `TABLE`";
$stmt = $db->prepare($query);
$stmt->execute();
$rows = $stmt->fetch();
foreach($rows as $row) {
    echo $row['VALUE1'];
    echo $row['VALUE2'];
    echo $row['VALUE3'];
}
?>

It only echo's the first letter of each value.

Here is what my table looks like:

VALUE1 VALUE2 VALUE3
gomeow book   nothing
other  book   nothing

It only prints out the first letter of the first row many times Prints out: ggggggbbbbbbnnnnnn

Check your error logs, and try with this and let me know then -

$rows = $stmt->fetch(PDO::FETCH_BOTH);
print_r($rows);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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