简体   繁体   English

我的openshift应用程序PDO查询不起作用

[英]My openshift application PDO query didn't work

I am try to connect phpmyadmin database using my php script in openshift 我尝试在openshift中使用我的PHP脚本连接phpmyadmin数据库

but the result is a empty page. 但结果是一个空白页。

then, I find the question is the query didn't work 然后,我发现问题是查询不起作用

but I don't know why 但我不知道为什么

There is my original code 有我的原始密码

try{
        $dsn = 'mysql:dbname=exampleDataBase;host=127.**.***.***;port=*****';
        $dbh = new PDO($dsn, "account", "password");
        $sth = $dbh->prepare('SELECT * FROM test1');
        $fin = $sth->execute();
        while($row = $sth->fetch(PDO::FETCH_ASSOC)){
            print_r($row);
        }
    } catch (PDOException $e){
        echo "Sytan error" . $e -> getMessage();
    }
    $dbh = null;

and the result is a empty page, so I modify my code 结果是一个空白页,所以我修改了我的代码

There is my modify code 有我的修改代码

try{
        $dsn = 'mysql:dbname=exampleDataBase;host=127.**.***.***;port=*****';
        $dbh = new PDO($dsn, "account", "password");
        $sth = $dbh->prepare('jngfcjfgcnmgcm,,hmnxf');
        $fin = $sth->execute();
        while($row = $sth->fetch(PDO::FETCH_ASSOC)){
            print_r($row);
        }
    } catch (PDOException $e){
        echo "Sytan error" . $e -> getMessage();
    }
    $dbh = null;

I input the wrong query sytanx(jngfcjfgcnmgcm,,hmnxf), but it didn't return error. 我输入了错误的查询sytanx(jngfcjfgcnmgcm ,, hmnxf),但未返回错误。

You modified your code to a wrong statement to see the error message? 您将代码修改为错误的语句以查看错误消息? You have your PHP errors turned off, when doing a statement like: 执行以下语句时,您已关闭PHP错误:

$sth = $dbh->prepare('jngfcjfgcnmgcm,,hmnxf');

You would receive an error like: 您将收到类似以下的错误:

Sytan error SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; Sytan错误 SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有错误;请参见语法错误。 check the manual that corresponds to your MySQL server version for the right syntax to use near 'jngfcjfgcnmgcm,,hmnxf' at line 1 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'jngfcjfgcnmgcm ,, hmnxf'附近使用

What do you exactly want? 你到底想要什么 The exception is not showing? 没有显示异常?

Add this to your script see your errors 将此添加到脚本中,查看错误

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);
ini_set('html_errors', 1);

and change your query code to this, see notes 并将查询代码更改为此,请参阅注释

  try{
    //port=***** is only need where its different from the default
    $dsn = 'mysql:host=localhost;dbname=exampleDataBase';
    $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
    $dbh = new PDO($dsn, "account", "password", $options);
    $sth = $dbh->prepare('SELECT * FROM test1');
    // execute $sth
    $sth->execute();
    //Change fetch to fetchAll
    while($row = $sth->fetchAll(PDO::FETCH_ASSOC)){
        print_r($row);
    }
} catch (PDOException $e){
    echo "Sytan error" . $e->getMessage();
}

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

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