以下是按顺序排列的文本:
登录 -> 选择数据库 -> 从给定的卡片列表中选择 -> mysql-process 以生成测试列表 -> 选择一个测试 -> mysql-process 以根据所选卡片和测试生成批号。
一个脚本“mysql-process to generate a list of tests”正在工作,我可以选择其中一个测试。
然后错误弹出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');
}
});
收集测试2.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 ;
好的,完成了。请告知我哪里出错了。请参阅下面的附件:
//添加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);
?>