Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php pdo选择查询不';行不通_Php_Mysql_Pdo - Fatal编程技术网

php pdo选择查询不';行不通

php pdo选择查询不';行不通,php,mysql,pdo,Php,Mysql,Pdo,我是php PDO新手,我做了一个查询来选择数据库中的用户并将其显示在html表中,但没有得到任何结果,也没有错误消息打印($connexion)返回PDO对象() 这是代码。谢谢你的帮助 连接到db//connexion.php 查询文件//searchInvite.php 嗯,这是您的代码: PHP代码[index.PHP]: <!DOCTYPE HTML> <head> <meta charset="utf-8" </head> <htm

我是php PDO新手,我做了一个查询来选择数据库中的用户并将其显示在html表中,但没有得到任何结果,也没有错误消息<代码>打印($connexion)返回
PDO对象()

这是代码。谢谢你的帮助

连接到db//connexion.php 查询文件//searchInvite.php

嗯,这是您的代码:

PHP代码[index.PHP]:

<!DOCTYPE HTML>
<head>
<meta charset="utf-8" </head>
<html>
<body>
<table border="1px">
    <tr>
        <td>Nom</td>
        <td>Prenom</td>
        <td>Fonction</td>
    </tr>
<?php
require_once 'connection.php';
$DBH = connection();
# creating the statement
$STH = $DBH->prepare("SELECT nom, prenom, fonction, titre_grade, adr_pro_voie FROM invite ORDER BY id LIMIT 0 , 30");
# setting the fetch mode  
$STH->setFetchMode(PDO::FETCH_OBJ);
# run the query
if ( $STH->execute()){
# showing the results  
while($enregistrement = $STH->fetch()) {  
?>
    <tr>
        <td><?php echo $enregistrement->nom; ?></td>
        <td><?php echo $enregistrement->prenom; ?></td>
        <td><?php echo $enregistrement->fonction; ?></td>
        <td><?php echo $enregistrement->titre_grade ?></td>
        <td><?php echo $enregistrement->adr_pro_voie; ?></td>
    </tr>

<?php }
}else {
    // if not run pdo statement send error
    $error = $STH->errorInfo();
    echo $error[2];
} ?>

</table>
</body>
</html>
 1. Check your DB name
 2. Check your user name
 3. Check your password
 4. Check your server
 5. Check if user privilege access database
 6. Check table name, try to dry run query.
一些建议:

<!DOCTYPE HTML>
<head>
<meta charset="utf-8" </head>
<html>
<body>
<table border="1px">
    <tr>
        <td>Nom</td>
        <td>Prenom</td>
        <td>Fonction</td>
    </tr>
<?php
require_once 'connection.php';
$DBH = connection();
# creating the statement
$STH = $DBH->prepare("SELECT nom, prenom, fonction, titre_grade, adr_pro_voie FROM invite ORDER BY id LIMIT 0 , 30");
# setting the fetch mode  
$STH->setFetchMode(PDO::FETCH_OBJ);
# run the query
if ( $STH->execute()){
# showing the results  
while($enregistrement = $STH->fetch()) {  
?>
    <tr>
        <td><?php echo $enregistrement->nom; ?></td>
        <td><?php echo $enregistrement->prenom; ?></td>
        <td><?php echo $enregistrement->fonction; ?></td>
        <td><?php echo $enregistrement->titre_grade ?></td>
        <td><?php echo $enregistrement->adr_pro_voie; ?></td>
    </tr>

<?php }
}else {
    // if not run pdo statement send error
    $error = $STH->errorInfo();
    echo $error[2];
} ?>

</table>
</body>
</html>
 1. Check your DB name
 2. Check your user name
 3. Check your password
 4. Check your server
 5. Check if user privilege access database
 6. Check table name, try to dry run query.

您的查询中没有
:id
占位符。查询中的位置::id?我以前从未见过包含空格的$dsn$dns='mysql:host=localhost;dbname=pruf';Try:$dns='mysql:host=localhost;dbname=pruf';-只是一个想法。您好,谢谢您的回复。我已经删除了空格,显示了表格,但在每一行中,我都有一条错误消息:“在第40行尝试获取C:\wamp\www\sqlquery\searchinvests.php中非对象的属性”。谢谢您的回答。我已经删除了$stmt->bindParam(':id',$id,PDO::PARAM_INT);因为我想检索所有的用户,而不仅仅是一个特定的id。现在表显示出来了,但在每一行中,我都有一条错误消息:“试图在第40行的C:\wamp\www\sqlquery\searchinvests.php中获取非对象的属性”–@albe:用错误处理检查我的更新答案。非常感谢它现在可以工作了!您的欢迎:)您也可以使用PDO类包装器,好吧,我试试。
 1. Check your DB name
 2. Check your user name
 3. Check your password
 4. Check your server
 5. Check if user privilege access database
 6. Check table name, try to dry run query.