这是我的单一作业的简单搜索栏:
<form name="search" method="post" action="phone_search.php">
<font size="5">Best Secondhand Mobile Phones Geelong</font> - Search the site:
<input type="text" name="term" />
<input type="submit" name="search" value="Search" />
</form>
这是我访问oracle服务器的php代码:
echo "<h2>Results</h2>";
//Null string entered
if ($term == "")
{
echo "You didn't enter anything!\n";
exit;
}
//Connect to database
$dbuser = "xxxx";
$dbpass = "xxxx";
$db = "SSID";
$connect = OCILogon($dbuser, $dbpass, $db);
//Database connection error
if (!$connect)
{
echo "An error occurred connecting to the database.\n";
exit;
}
//Make all lowercase
$term = strtolower($term);
$query = "'SELECT * FROM Phones WHERE lower($Name) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($OS) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($Chipset) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($CPU) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($GPU) LIKE $term'";
//Perform search
$stmt = OCIParse($connect, $query);
//And display the results
$counter = 0;
while(OCIFetch($stmt))
{
$counter++;
echo OCIResult($stmt, "Name");
echo "<br>";
echo OCIResult($stmt, "OS");
echo "<br>";
echo OCIResult($stmt, "Chipset");
echo "<br>";
echo OCIResult($stmt, "CPU");
echo "<br>";
echo OCIResult($stmt, "GPU");
echo "<br>";
echo "<br>";
}
我得到了一个空字符串的正确错误,并且在输入内容时没有出现空错误。 但是,我认为这一行存在问题:
$query = "'SELECT * FROM Phones WHERE lower($Name) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($OS) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($Chipset) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($CPU) LIKE $term' OR 'SELECT * FROM Phones WHERE lower($GPU) LIKE $term'";
我一直收到这个错误:
Warning: ocifetch() [function.ocifetch]: ORA-24374: define not done before fetch or execute and fetch in /home/cstev/public_html/Assignment_2/phone_search.php on line 41
第41行是:
while(OCIFetch($stmt))
我在发布之前故意用“xxxx”替换了登录详细信息。
当我搜索此错误时,我得到:Error in PHP search function 好像其他人在2年前因同一个任务而遇到这个问题。 他得到的答案是他的搜索字词可能是空的。 我可以告诉我,如果输入的搜索词是空白的,那么根据空字符串错误消息正常工作,这不是同一个问题。
如果有人能指出我正确的方向,我会非常感激!!
供参考,这是我的数据库:
DROP TABLE Phones;
CREATE TABLE Phones
( Name VARCHAR2(50),
OS VARCHAR2(50),
Chipset VARCHAR(50),
CPU VARCHAR(50),
GPU VARCHAR2(50),
Image VARCHAR2(50)
);
INSERT INTO Phones VALUES ('HTC Butterfly S', 'Android OS, v4.2.2 (Jelly Bean)', 'Qualcomm APQ8064T Snapdragon 600', 'Quad-core 1.9 GHz Krait 300', 'Adreno 320', 'images/htc-butterfly-s (1).jpg');
INSERT INTO Phones VALUES ('Huawei Ascend P6', 'Android OS, v4.2.2 (Jelly Bean)', 'Huawei K3V2', 'Quad-core 1.5 GHz', 'N/A', 'images/huawei-ascend-p6-ofic.jpg');
INSERT INTO Phones VALUES ('Oppo R819', 'Android OS, v4.2.1 (Jelly Bean)', 'MediaTek MT6589', 'Quad-core 1.2 GHz', 'PowerVR SGX544', 'images/oppo-r819.jpg');
INSERT INTO Phones VALUES ('Sony Xperia M', 'Android OS, v4.1 (Jelly Bean)', 'Qualcomm Qualcomm Snapdragon S4 Plus MSM8227', 'Dual-core 1 GHz Krait', 'Adreno 305', 'images/sony-xperia-m (1).jpg');
INSERT INTO Phones VALUES ('Samsung Galaxy Core', 'Android OS, v4.1.2 (Jelly Bean)', 'Snapdragon MSM8225 S4 Play', 'Dual-core 1.2 GHz Cortex-A5', 'Adreno 203', 'images/samsung-galaxy-core-gt-i8260 (1).jpg');
INSERT INTO Phones VALUES ('Motorola Moto X', 'Android OS, v4.2.2 (Jelly Bean)', 'Qualcomm MSM8960Pro Snapdragon', 'Dual-core 1.7 GHz Krait', 'Adreno 320', 'images/moto-x.jpg');
commit;
答案 0 :(得分:4)
我猜你忘记了
ociexecute($stmt, OCI_DEFAULT);
之后
$stmt = OCIParse($connect, $query);
之前:
while(OCIFetch($stmt))
所以它看起来像这样:
//Perform search
$stmt = OCIParse($connect, $query);
// Execute statement
ociexecute($stmt, OCI_DEFAULT);
//And display the results
$counter = 0;
while(OCIFetch($stmt))
{
$counter++;
...