0
據我所知explode
與my_sql
和PDO
無關。我有一個愚蠢的懷疑,並想知道如果有人能解釋我這一點。未定義的索引錯誤
我有我解析對於具有類似數據的特定標籤(腳本),一個XML文件 -
scripts/testSuite/UTA/CLI/CommonCli/commonSflow.tcl
scripts/testSuite/UTA/CLI/CommonCli/commonRoutePolicyDisplay.tcl
scripts/testSuite/networkSecurity/802dot1x/802dot1xBasicFunctionality/802dot1xSuppliSuccessAuth.tcl
scripts/testSuite/hostAgentFeatures/debugLogging/debugLoggingFeatureTesting/DebugLogging_F_SshErrorMsg.tcl
scripts/testSuite/sdnSTC/Flare/Backup_Restore/Sprint16_tests/Backup_Restore_RestoreModeOFFRestore.tcl
我們解析這個我使用的代碼 - 上
<?php
include_once ("db_connection.php");
$xml=simplexml_load_file('info.xml');
foreach($xml->testcase as $var)
{
$var=explode('/',$var->script);
print_r($var);
$module[] =$var[2];
$testName[] = end($var);
}
$modules = array_unique($module);
foreach($modules as $newarr)
{
$newmodules[]=$newarr;
}
?>
另一方面我有一個數據庫,其中包含與xml相同的數據的列namde腳本。爲此,我現在用的代碼 -
<?php
include_once ("db_connection.php");
$conn = testdb_connect();
$testType = 'TCL';
$sth = $conn->prepare('SELECT script FROM testcases2 WHERE testcases2.testType = :testType');
$sth->execute(array(':testType' => $testType));
while($row = $sth->fetch(PDO::FETCH_ASSOC))
{
foreach($row as $key)
{
$var=explode('/', $key);
print_r($var);
$module[] =$var[2];
}
}
$modules = array_unique($module);
foreach($modules as $newarr)
{
$newmodules[]=$newarr;
}
?>
在這兩種情況下,print_r($var);
輸出是一樣這就好比 - output。
問題是這裏,當我運行我的my_sql代碼時,我得到沒有錯誤,但與PDO我得到這個undefined index 2 error
。
PDO代碼有什麼問題?請指導 。
試$模塊[] =(空(是$ var [2])是$ var [2]!? '');可能是索引2是空的 –
'$ module [] = $ var [2];'這個'$ var [2]'不存在。檢查$ var內部的內容。 –
print_r($ var);輸出就像[var](http://pastebin.com/VVCKfCBa) – Newbie