php不执行sql查询超时

标签 php mysql

我正在尝试删除“occupation_data”(表)的一些行,但是有一个外部约束,所以我做了一个小的 php 脚本来删除其他表中链接的数据,然后在 occupation_data 中删除它。

当我运行脚本时,我在浏览器中看到加载但什么也没有出现,我应该使用什么工具来调试它?

谢谢

高迪曼

这是我的代码:

<?php
error_reporting(E_ALL);
set_time_limit(60000); // There are more than 30 tables and 380 primary key to delete, may take time
ini_set("display_errors", 1);


$tupleasup = array(
    '13-1199.05',
    '13-1023.00',
    '13-1022.00',
    '53-6031.00'
); //Contain the primary key of the row


$table = array(
    'abilities',
    'education_training_experience',
    'green_occupations',
    'occupation_data'
);

try {
    $VALEUR_hote         = '**********';
    $VALEUR_port         = '******';
    $VALEUR_nom_bd       = '********';
    $VALEUR_user         = '*******';
    $VALEUR_mot_de_passe = '*******'; //Working connection setting

    $connexion = new PDO('mysql:host=' . $VALEUR_hote . ';port=' . $VALEUR_port . ';dbname=' . $VALEUR_nom_bd, $VALEUR_user, $VALEUR_mot_de_passe);
    $connexion->exec("SET NAMES 'UTF8'");
    $connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    echo "toto"; // This message is not displayed

    foreach ($tupleasup as $codeOnet) {

        foreach ($table as $nomTable) {
            $query     = "DELETE FROM " . $nomTable . " WHERE onetsoc_code =" . $codeOnet;
            $resultats = $connexion->query($query);
        }
        echo "Supprimé" . $codeOnet; // This message is not displayed too.

    }
}
catch (PDOException $e) {
    echo 'Échec lors de la connexion : ' . $e->getMessage();
}



?>

最佳答案

只是为了调试和检查连接是否正常将您的代码转换为:

try {
    $VALEUR_hote         = '**********';
    $VALEUR_port         = '******';
    $VALEUR_nom_bd       = '********';
    $VALEUR_user         = '*******';
    $VALEUR_mot_de_passe = '*******'; //Working connection setting

    $connexion = new PDO('mysql:host=' . $VALEUR_hote . ';port=' . $VALEUR_port . ';dbname=' . $VALEUR_nom_bd, $VALEUR_user, $VALEUR_mot_de_passe);
}
catch (PDOException $e) {
    echo 'Échec lors de la connexion : ' . $e->getMessage();
    $connexion = false;
}

if ($connexion != false) {
  $connexion->exec("SET NAMES 'UTF8'");
  echo "toto"; // This message is not displayed
  foreach ($tupleasup as $codeOnet) {

    foreach ($table as $nomTable) {
        $query     = "DELETE FROM `$nomTable` WHERE onetsoc_code = :code";
        $sth = $connexion->prepare($query);
        $sth->bindParam(':code',$codeOnet);
        if (! $sth->execute() ) {
          $arr = $sth->errorInfo();
          print_r($arr);
        }
    }
    echo "Supprimé" . $codeOnet; // This message is not displayed too.

}

关于php不执行sql查询超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29947498/

相关文章:

php - PostgreSQL : getting error messages from `pg_convert()`

php - laravel 中的 JSON 搜索 Eloquent

php - 我如何在 symfony3 中使用 "INSERT SELECT"?

mysql - 优化通过 has_many :through association 检索 ID 的方式

现场 PHP session 问题但不是本地问题

php - Group By day and month 原则

php - 用枚举类型提示?

php - 命名空间 - 到 'use' 或不到 'use' ?

mysql - 如果其中一个条目满足特定条件,则删除一组中的所有条目

如果特定日期不存在,MySQL 查询将针对属性返回零