1

ここに順番にテキストがあります:

ログイン -> データベースを選択 -> 特定のカードのリストから選択 -> mysql-process でテストのリストを生成 -> テストを選択 -> mysql-process で選択したカードとテストに基づいてバッチ番号を生成

スクリプト「テストのリストを作成するためのmysqlプロセス」が機能しており、テストの1つを選択できます。

その後、エラーがポップアップしexception 'PDOException' with message 'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected'ます。

データベースが既に選択されているにもかかわらず、データベースが選択されていないというエラーが表示されるのはなぜですか。

2 つの php ファイルがあります: gathertests2.php(動作中) とgatherbatches.php(動作していない)。

main.php(抜粋1)

on(selPCBA, 'change', function(value)
{console.debug('value = '+value);
var selectedPCBA = this.get('displayedValue');
console.debug('Contents of "selected" variable ='+selectedPCBA);
var selTest = registry.byId('ID_selTest');
    if (selectedPCBA.indexOf("class='inUse'")!==-1)
         {request.post('gathertests2.php',
    {data:{testDB : value},
    handleAs: "json"}).then
    (
         function(response)
        {var memoStore1 = new Memory({data:response});
                selTest.set('store', memoStore1);
            selTest.set('value','');
        },
     function(error)
            {alert("Test's Error:"+error);
    });
         selTest.startup();
    }
   else
     {console.debug('Error:- Attempting to select the unavailable card');
      alert('Please select the only highlighted card');
}
});

collecttests2.php

<?php
    require_once($_SERVER['DOCUMENT_ROOT'] . '/firephp_include.php');
$firephp->setEnabled(TRUE);
$firephp->info('Start debugging in gathertest2.php');
require_once '../scripts/login.php';
    $db = $_POST['testDB'];
$stmt_use = $dbh->prepare("use $db");//ok
$firephp->fb($stmt_use);

    try //PDO Driver is used in PHP for working with MySQL!!!!
    {
        $stmt_use  -> execute();//ok
        $firephp->log("Successfully executed!");
    }

    catch (PDOException $err) //PDOException is declared in login.php
    {
        $alertmsg = $err->getMessage();
        include 'alertmessage.php';
        $firephp->error("Unsuccessfully executing: $err");
    }
    $stmt_call1 = $dbh->prepare('call listmfg_codes()');
$firephp->fb($stmt_call1);

    try //PDO Driver is used in PHP for working with MySQL!!!!
    {
        $stmt_call1->execute();
        $firephp->log("Successfully executed!");
    }

    catch (PDOException $err) //PDOException is declared in login.php
    {
        $alertmsg = $err->getMessage();
        include 'alertmessage.php';
        $firephp->error("Unsuccessfully executing: $err");
    }

$result = $stmt_call1->fetchAll(PDO::FETCH_ASSOC); //ok
$output = json_encode($result); 
echo $output;
$firephp -> fb($result);
$firephp -> info("End");

どこcall listmfg_codes()ですか

DELIMITER $$
DROP PROCEDURE IF EXISTS `testdata2060_03`.`listmfg_codes` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `listmfg_codes`()
BEGIN
select distinct(mfg_code) from test order by mfg_code asc;
END $$
DELIMITER ;

main.php(抜粋2)

on(selTest, 'change', function(value)
    {var selectedTest = this.get('displayedValue');
 var selBatch = registry.byId('ID_selBatch');
 request.post('gatherbatches.php',
    {data:{testCard : value},
     handleAs: "json"}).then
(
    function(response)
    {var memoStore2 = new Memory({data:response});
     selBatch.set('store', memoStore2);
    selBatch.set('value','');
    },
   function(error)
       {alert("Batch's Error:"+error);
    }
);
       selBatch.startup();
 });

収集バッチ.php

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/firephp_include.php');
$firephp->setEnabled(TRUE);
$firephp->warn('Start debugging in gatherbatches.php');
require_once '../scripts/login.php';
    $card = $_POST['testCard'];//must add '' in "" bracket for call command to work
$stmt_call2 = $dbh->prepare("call listbatch('$card')");
$firephp->fb($stmt_call2);
try //PDO Driver is used in PHP for working with MySQL!!!!
    {
        $stmt_call2->execute();
        $firephp->log("Successfully executed!");
    }

catch (PDOException $err) //PDOException is declared in login.php
    {
        $alertmsg = $err->getMessage();
        include 'alertmessage.php';
        $firephp->error("Unsuccessfully executing: $err");  
        }

$result = $stmt_call2->fetchAll(PDO::FETCH_ASSOC); //ok
    $output = json_encode($result); 
echo $output;
$firephp -> fb($result);
$firephp -> warn("End");

どこcall listbatch()ですか

 DELIMITER $$
 DROP PROCEDURE IF EXISTS `testdata2060_03`.`listbatch` $$
 CREATE DEFINER=`root`@`localhost` PROCEDURE `listbatch`(mfgnum VARCHAR(24))
 BEGIN
     SELECT batch FROM test WHERE mfg_code = mfgnum group by batch order by batch desc;
 END $$
 DELIMITER ; 

OK 完了です。どこが間違っているか教えてください。以下の添付ファイルを参照してください。

ここに画像の説明を入力

// login.php を追加

<?php 
   $dsn = 'mysql:host=localhost;Port=3306';
   $user = 'root'; $pswd = '';
   $dbh = new PDO($dsn, $user, $pswd, array(PDO::ATTR_PERSISTENT, TRUE));     
   $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
   $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 
  ?>
4

1 に答える 1