튜토리얼에서이 코드를 선택하고 편집하여 필요에 맞게 수정했습니다. 내가 코드를 실행할 때치명적인 오류, 클래스를 찾을 수 없습니다.
<?php
//if we got something through $_POST
if (isset($_POST['search'])) {
// here you would normally include some database connection
include('config2.php');
$db = new db();
// never trust what user wrote! We must ALWAYS sanitize user input
$word = mysql_real_escape_string($_POST['search']);
// build your search query to the database
$sql = "SELECT name FROM $tbl_name WHERE name LIKE '%" . $word . "%'";
// get results
$row = $db->select_list($sql);
if(count($row)) {
$end_result = '';
foreach($row as $r) {
$result = $r['title'];
// we will use this to bold the search word in result
$bold = '<span class="found">' . $word . '</span>';
$end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>';
}
echo $end_result;
} else {
echo '<li>No results found</li>';
}
}
?>
나는이 오류가 무엇입니까 :
Fatal error: Class 'db' not found in /home/peltdyou/public_html/do_search.php on line 6
을 내가 PHP 매우 새로운 오전 그래서 사람이 .. 내 문제에 도움이 되거 수
UPDATE :
<?php
class db {
function __construct()
{
global $dbh;
if (!is_null($dbh)) return;
$dbh = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME);
mysql_query('SET NAMES utf8');
}
function select_list($query)
{
$q = mysql_query($query);
if (!$q) return null;
$ret = array();
while ($row = mysql_fetch_array($q, MYSQL_ASSOC)) {
array_push($ret, $row);
}
mysql_free_result($q);
return $ret;
}
}
?>
이것은 db.php 코드입니다.이 파일을 내 config2.php 파일로 바꾸면 연결될 수 있다고 생각했습니다. 내 데이터베이스 ...을 분명히하지
'db.php'를 포함하는 것을 잊었습니까? 클래스'db'를 정의하는 include 파일이 없습니다. – Ryan
PHP에서 db 클래스를 찾을 수 없다고 알려줍니다. 응용 프로그램에 자동로드되지 않았거나 경로가 잘못되었거나 존재하지 않기 때문일 수 있습니다. 어떻게 db 클래스를 포함하고 있습니까? 게시 할 수있는 다른 코드가 있습니까? – Haroon
설정 파일에 무엇이 들어 있는지 알 수는 없지만 둘 다 별도로 포함 할 수 있습니다 (기능적으로 다를 수 있습니다). – GDP