Fatal error: require once

Reply

Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Fatal error: require once

 
0
  #1
Feb 21st, 2008
I have absolutly no idea what this error means or what it requires me to do but i'm getting this error message:

Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'DOC__ROOT/library/classes/class_dao.php' (include_path='C:\Program Files\Zend\ZendStudio-5.5.1\bin\ZendFramework\library') in C:\xampp\htdocs\capat\library\classes\class_engcis.php on line 18

this is class_engcis.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * engCIS local version
  6.  *
  7.  */
  8. function & rel($struc, &$file) {
  9. return file_exists( ( $file = ( dirname($struc).'/'.$file ) ) );
  10. }
  11.  
  12. function relativetome($structure, $filetoget){
  13. return rel($structure,$filetoget) ? require_once($filetoget) : null;
  14. }
  15.  
  16. relativetome(__FILE__, 'inc_global.php');
  17.  
  18. require_once(DOC__ROOT . '/library/classes/class_dao.php');
  19. require_once(DOC__ROOT . '/library/functions/lib_array_functions.php');
  20.  
  21.  
  22. class EngCIS {
  23. // Public Vars
  24.  
  25.  
  26. // Private Vars
  27. private $_DAO = null;
  28. private $_ordering_types = null;
  29.  
  30. /**
  31. * CONSTRUCTOR
  32. */
  33. function EngCIS() {
  34. $this->_DAO = new DAO(APP__DB_HOST,APP__DB_DATABASE,APP__DB_PASSWORD,APP__DB_DATABASE);
  35. $this->_DAO->set_debug(false);
  36. }// /->EngCIS()
  37.  
  38.  
  39. /*
  40. * ================================================================================
  41. * Public Methods
  42. * ================================================================================
  43. */
  44.  
  45.  
  46. /*
  47. * --------------------------------------------------------------------------------
  48. * Course Methods
  49. * --------------------------------------------------------------------------------
  50. */
  51.  
  52.  
  53. /**
  54. * Get array of courses for a department
  55. * @param string $department_id ID of department to search
  56. * @param string $ordering ordering mode
  57. * @return array
  58. */
  59. /** function get_department_courses($department_id, $ordering = 'name') {
  60. $order_by_clause = $this->_order_by_clause('course', $ordering);
  61.  
  62. return $this->_DAO->fetch( "
  63. SELECT lcc.*
  64. FROM live_cis_course lcc
  65. WHERE department_id='$department_id'
  66. $order_by_clause
  67. ");
  68. }// /->get_department_courses()
  69. */
  70.  
  71. /**
  72. * Get course info as an array
  73. * @param integer $course_id
  74. * @return array
  75. */
  76. /** function get_course($course_id) {
  77. return $this->_DAO->fetch_row( "SELECT lcc.*
  78. FROM live_cis_course lcc
  79. WHERE course_id='$course_id'
  80. ");
  81. }// /->get_course()
  82. */
  83.  
  84. /**
  85. * Get array of students for course
  86. *
  87. * @param string $ordering ordering mode
  88. *
  89. * @return array assoc-array of student info
  90. */
  91. /** function get_course_students($course_id, $ordering = 'name') {
  92. $order_by_clause = $this->_order_by_clause('student', $ordering);
  93.  
  94. return $this->_DAO->fetch( "
  95. SELECT lcs.*
  96. FROM live_cis_student lcs INNER JOIN live_student_module lcsm ON lcs.student_id=lcsm.student_id AND module_id='$module_id'
  97. WHERE course_id='$course_id'
  98. $order_by_clause
  99. ");
  100. }// /->get_course_students()
  101. */
  102.  
  103. /*
  104. * --------------------------------------------------------------------------------
  105. * Module Methods
  106. * --------------------------------------------------------------------------------
  107. */
  108.  
  109.  
  110. /**
  111. * Get module info as an array
  112. *
  113. * @param string/array $module_id module ID(s) to search for
  114. * @param string $ordering ordering mode
  115. *
  116. * @return array either an assoc-array of module info or an array of assoc-arrays, containing many modules' info
  117. */
  118. function get_module($modules = null, $ordering = 'id') {
  119. $module_search = $this->_DAO->build_filter('module_code', (array) $modules);
  120. $order_by_clause = $this->_order_by_clause('module', $ordering);
  121.  
  122. // If there's more than one module to search for, get all the rows
  123. if (is_array($modules)) {
  124. return $this->_DAO->fetch("SELECT lcm.module_code AS module_id, lcm.module_title
  125. FROM module lcm
  126. WHERE $module_search
  127. $order_by_clause");
  128. } else { // else, just return one row
  129. if (!empty($modules)) {
  130. return $this->_DAO->fetch_row("SELECT lcm.module_code AS module_id, lcm.module_title
  131. FROM module lcm
  132. WHERE $module_search
  133. LIMIT 1");
  134. }
  135. }
  136. }// /->get_module()
  137.  
  138.  
  139. /**
  140. * Get array of staff for module
  141. * @param integer $module_id
  142. * @param string $ordering
  143. * @return array
  144. */
  145. function get_module_staff($module_id, $ordering) {
  146. $order_by_clause = $this->_order_by_clause('staff', $ordering);
  147.  
  148. return $this->_DAO->fetch ("SELECT lcs.*
  149. FROM user lcs
  150. INNER JOIN user_module lcsm ON lcs.user_id = lcsm.user_id
  151. WHERE lcs.user_type = 'staff'
  152. AND module_id='$module_id'
  153. $order_by_clause");
  154. }// /->get_module_staff()
  155.  
  156.  
  157. /**
  158. * Get array of students for one or more modules
  159. * @param integer $modules
  160. * @param string $ordering
  161. * @return array
  162. */
  163. function get_module_students($modules, $ordering = 'name') {
  164. $module_set = $this->_DAO->build_set($modules);
  165. $order_by_clause = $this->_order_by_clause('student', $ordering);
  166.  
  167. return $this->_DAO->fetch(" SELECT DISTINCT lcs.*, lcs.lastname AS surname, institutional_reference AS student_id
  168. FROM user lcs
  169. INNER JOIN user_module lcsm ON lcs.user_id=lcsm.user_id AND module_id IN $module_set
  170. WHERE lcs.user_type = 'student'
  171. $order_by_clause
  172. ");
  173. }// /->get_module_students()
  174.  
  175.  
  176. /**
  177. * Get total number of students on one or more modules
  178. *
  179. * @param array $modules modules to count students for
  180. * @return array
  181. */
  182. function get_module_students_count($modules) {
  183. $module_set = $this->_DAO->build_set($modules);
  184.  
  185. $sql = "SELECT COUNT(DISTINCT u.user_id)
  186. FROM user u
  187. INNER JOIN user_module um ON u.user_id=um.user_id
  188. INNER JOIN module m ON m.module_code=um.module_id
  189. WHERE m.module_code IN $module_set
  190. AND u.user_type = 'student'";
  191. return $this->_DAO->fetch_value($sql);
  192. }// /->get_module_students_count
  193.  
  194.  
  195. /**
  196. * Get an array of student IDs for students on the given modules
  197. * @param array $modules modules to count students for
  198. * @return array
  199. */
  200. function get_module_students_id($modules) {
  201. if (!empty($modules)) {
  202. $module_set = $this->_DAO->build_set( (array) $modules);
  203. return $this->_DAO->fetch_col("SELECT DISTINCT u.institutional_reference AS staff_id
  204. FROM user u
  205. INNER JOIN user_module um ON u.user_id=um.user_id
  206. INNER JOIN module m ON m.module_code=um.module_id
  207. WHERE m.module_code IN $module_set
  208. AND u.user_type = 'student'
  209. ORDER BY u.user_id ASC");
  210. }
  211. }// /->get_module_students_id()
  212.  
  213.  
  214. /**
  215. * Get an array of user IDs for students on the given modules (user_id = 'student_{studentID}'
  216. * @param array $modules modules to count students for
  217. * @return array
  218. */
  219. function get_module_students_user_id($modules) {
  220. if (!empty($modules)) {
  221. $module_set = $this->_DAO->build_set( (array) $modules);
  222. $sql = "SELECT DISTINCT u.user_id
  223. FROM user u
  224. INNER JOIN user_module um ON u.user_id=um.user_id
  225. INNER JOIN module m ON m.module_code=um.module_id
  226. WHERE m.module_code IN $module_set
  227. AND u.user_type = 'student'
  228. ORDER BY u.user_id ASC
  229. ";
  230. return $this->_DAO->fetch_col($sql);
  231. }
  232. }// /->get_module_students_user_id()
  233.  
  234.  
  235. /**
  236. * Get number of students on individual multiple modules, grouped by module
  237. *
  238. * @param array $modules modules to count students for
  239. * @return array
  240. */
  241. function get_module_grouped_students_count($modules) {
  242. $module_search = $this->_DAO->build_filter('module_id', (array) $modules, 'OR');
  243.  
  244. return $this->_DAO->fetch_assoc("SELECT module_id, COUNT(user_id)
  245. FROM user_module lcsm
  246. WHERE $module_search
  247. GROUP BY module_id
  248. ORDER BY module_id");
  249. }// ->get_modules_grouped_students_count()
  250.  
  251.  
  252. /*
  253. * --------------------------------------------------------------------------------
  254. * Staff Methods
  255. * --------------------------------------------------------------------------------
  256. */
  257.  
  258.  
  259. /**
  260. * Get staff info
  261. * Can work with either staff_id or staff_username alone (staff_id takes precedent)
  262. *
  263. * @param string/array $staff_id staff ID(s) to search for (use NULL if searching on username)
  264. * @param string/array $staff_username staff username(s) to search for
  265. * @param string $ordering ordering mode
  266. *
  267. * @return array either an assoc-array of staff member info or an array of assoc-arrays, containting many staff members' info
  268. */
  269. function get_staff($staff_id, $staff_username = null, $ordering = 'name') {
  270. if ($staff_id) {
  271. $staff_set = $this->_DAO->build_set($staff_id);
  272. $sql_WHERE = "user_id IN $staff_set ";
  273. } else {
  274. if ($staff_username) {
  275. $staff_set = $this->_DAO->build_set($staff_username);
  276. $sql_WHERE = "username IN $staff_set ";
  277. } else { return null; }
  278. }
  279.  
  280. $order_by_clause = $this->_order_by_clause('staff', $ordering);
  281.  
  282. // If there's more than one staff member to search for, get all the rows
  283. if ( (is_array($staff_id)) || (is_array($staff_username)) ) {
  284. return $this->_DAO->fetch("SELECT lcs.*, lcs.lastname AS surname, institutional_reference AS staff_id
  285. FROM user lcs
  286. WHERE $sql_WHERE
  287. $order_by_clause");
  288. } else { // else, just return one row
  289. return $this->_DAO->fetch_row("SELECT lcs.*, lcs.lastname AS surname, institutional_reference AS staff_id
  290. FROM user lcs
  291. WHERE $sql_WHERE
  292. LIMIT 1");
  293. }
  294. }// /->get_staff()
  295.  
  296.  
  297. /**
  298. * Get array of modules for the given staff member(s)
  299. * Can work with either staff_id or staff_username alone (staff_id takes precedent)
  300. *
  301. * @param string/array $staff_id staff ID(s) to search for (use NULL if searching on username)
  302. * @param string/array $staff_username staff username(s) to search for
  303. * @param string $ordering ordering mode
  304. *
  305. * @return array an array of assoc-arrays, containting many module info
  306. */
  307. function get_staff_modules($staff_id, $staff_username = null, $ordering = 'id') {
  308. if ($staff_id) {
  309. $staff_set = $this->_DAO->build_set($staff_id);
  310. $sql_WHERE = "user_id IN $staff_set ";
  311. } else {
  312. if ($staff_username) {
  313. $staff_set = $this->_DAO->build_set($staff_username);
  314. $sql_WHERE = "username IN $staff_set ";
  315. } else { return null; }
  316. }
  317.  
  318. $order_by_clause = $this->_order_by_clause('module', $ordering);
  319.  
  320. return $this->_DAO->fetch( "SELECT DISTINCT lcm.module_code AS module_id, lcm.module_title
  321. FROM module lcm INNER JOIN user_module lcsm ON lcm.module_code=lcsm.module_id
  322. WHERE $sql_WHERE
  323. $order_by_clause");
  324. }// /->get_staff_modules
  325.  
  326.  
  327. /**
  328. * Is the given staff member associated with the given modules?
  329. *
  330. * @param string $staff_id staff id of member being checked
  331. * @param string/array $module_id either a single module_id, or an array of module_ids
  332. * @return integer
  333. */
  334. function staff_has_module($staff_id, $module_id) {
  335. $module_id = (array) $module_id;
  336. $staff_modules = $this->get_staff_modules($staff_id);
  337. if (!$staff_modules) {
  338. return false;
  339. } else {
  340. $arr_module_id = array_extract_column($staff_modules, 'module_id');
  341. $diff = array_diff($module_id, $arr_module_id);
  342.  
  343. // If the array is empty, then the staff member has those modules
  344. return (count(array_diff($module_id, $arr_module_id))===0);
  345. }
  346. }// /->staff_has_module()
  347.  
  348.  
  349. /*
  350. * --------------------------------------------------------------------------------
  351. * Student Methods
  352. * --------------------------------------------------------------------------------
  353. */
  354.  
  355.  
  356. /**
  357. * Get student info
  358. * Can work with either student_id or student_username alone (student_id takes precedent)
  359. *
  360. * @param string/array $student_id student ID(s) to search for (use NULL if searching on username)
  361. * @param string/array $student_username student
  362. * @param string $ordering ordering mode
  363. *
  364. * @returns array either an assoc-array of student info or an array of assoc-arrays, containting many students info
  365. */
  366. function get_student($student_id = null, $student_username = null, $ordering = 'name') {
  367. if ($student_id) {
  368. $student_set = $this->_DAO->build_set($student_id);
  369. $sql_WHERE = "user_id IN $student_set ";
  370. } else {
  371. if ($student_username) {
  372. $student_set = $this->_DAO->build_set($student_username);
  373. $sql_WHERE = "username IN $student_set ";
  374. } else { return null; }
  375. }
  376.  
  377. // If there's more than one student to search for, get all the rows
  378. if ( (is_array($student_id)) || (is_array($student_username)) ) {
  379. $order_by_clause = $this->_order_by_clause('student', $ordering);
  380. return $this->_DAO->fetch("SELECT lcs.*, lcs.lastname AS surname, institutional_reference AS student_id
  381. FROM user lcs
  382. WHERE $sql_WHERE
  383. $order_by_clause");
  384. } else { // else, just return one row
  385. return $this->_DAO->fetch_row("SELECT lcs.*, lcs.lastname AS surname, institutional_reference AS student_id
  386. FROM user lcs
  387. WHERE $sql_WHERE
  388. LIMIT 1");
  389. }
  390. }// /->get_student()
  391.  
  392.  
  393. /**
  394. * Get array of modules for the given student(s)
  395. * Can work with either student_id or student_username alone (student_id takes precedent)
  396. *
  397. * @param string/array $student_id student ID(s) to search for (use NULL if searching on username)
  398. * @param string/array $student_username student username(s) to search for
  399. * @param string $ordering ordering mode
  400. *
  401. * @return array an array of module info arrays
  402. */
  403. function get_student_modules($student_id, $student_username = null, $ordering = 'id') {
  404. if ($student_id) {
  405. $student_set = $this->_DAO->build_set($student_id);
  406. $sql_WHERE = "user_id IN $student_set ";
  407. } else {
  408. if ($student_username) {
  409. $student_set = $this->_DAO->build_set($student_username);
  410. $sql_WHERE = "username IN $student_set ";
  411. } else { return null; }
  412. }
  413.  
  414. $order_by_clause = $this->_order_by_clause('module', $ordering);
  415.  
  416. return $this->_DAO->fetch( "SELECT DISTINCT lcm.module_code AS module_id, lcm.module_title
  417. FROM module lcm INNER JOIN user_module lcsm ON lcm.module_code=lcsm.module_id
  418. WHERE $sql_WHERE
  419. $order_by_clause");
  420. }// /->get_student_modules()
  421.  
  422.  
  423. /*
  424. * --------------------------------------------------------------------------------
  425. * User Methods
  426. * --------------------------------------------------------------------------------
  427. */
  428.  
  429.  
  430. /**
  431. * Get a user's info
  432. *
  433. * @param string/array $user_id user ID(s) to search for
  434. * $ordering : (string) - ordering mode
  435. *
  436. * Returns : either an assoc-array of user info
  437. * or an array of assoc-arrays, containting many users' info
  438. */
  439. function get_user($user_id, $ordering = 'name') {
  440. $user_set = $this->_DAO->build_set($user_id);
  441. $sql_WHERE = "user_id IN $user_set ";
  442.  
  443.  
  444. // If there's more than one user to search for, get all the rows
  445. if (is_array($user_id)) {
  446. $order_by_clause = $this->_order_by_clause('user', $ordering);
  447. $sql = "SELECT scu.*, scu.lastname AS surname
  448. FROM user scu
  449. WHERE $sql_WHERE
  450. $order_by_clause";
  451.  
  452. return $this->_DAO->fetch($sql);
  453. } else { // else, just return one row
  454. $sql = "SELECT scu.*, scu.lastname AS surname
  455. FROM user scu
  456. WHERE $sql_WHERE
  457. LIMIT 1";
  458. return $this->_DAO->fetch_row($sql);
  459. }
  460. }// /->get_user()
  461.  
  462.  
  463.  
  464. /**
  465. * Get a user's info by searching on email address
  466. *
  467. * @param string $email email address to search for
  468. *
  469. * Returns : an assoc-array of user info
  470. */
  471. function get_user_for_email($email) {
  472. return $this->_DAO->fetch_row("SELECT scu.*
  473. FROM user scu
  474. WHERE email='$email'
  475. LIMIT 1");
  476. }// /->get_user_for_email()
  477.  
  478.  
  479.  
  480.  
  481. /*
  482. * ================================================================================
  483. * Private Methods
  484. * ================================================================================
  485. */
  486.  
  487.  
  488. /**
  489. * Return an ORDER BY clause matching the given parameters
  490. *
  491. * @param string $row_type type of row being ordered. ['course','module','staff','student']
  492. * @param string $ordering type of ordering to do. ['id','name']
  493. *
  494. * @return string SQL ORDER BY clause of the form 'ORDER BY fieldname' or NULL if row_type/ordering are invalid
  495. */
  496. function _order_by_clause($row_type, $ordering = null) {
  497. if (!is_array($this->_ordering_types)) {
  498. // All available ordering types
  499. $this->_ordering_types = array (
  500. /** 'course' => array (
  501. 'id' => 'lcc.course_id' ,
  502. 'name' => 'lcc.course_title' ,
  503. ) ,
  504. */
  505. 'module' => array (
  506. 'id' => 'lcm.module_id' ,
  507. 'name' => 'lcm.module_title' ,
  508. ) ,
  509. 'staff' => array (
  510. 'id' => 'lcs.user_id' ,
  511. 'name' => 'lcs.lastname, lcs.forename' ,
  512. ) ,
  513. 'student' => array (
  514. 'id' => 'lcs.user_id' ,
  515. 'name' => 'lcs.lastname, lcs.forename' ,
  516. ) ,
  517. 'user' => array (
  518. 'id' => 'scu.user_id' ,
  519. 'name' => 'scu.lastname, scu.forename' ,
  520. ) ,
  521. );
  522. }
  523.  
  524. if ( (array_key_exists($row_type, $this->_ordering_types)) && (array_key_exists($ordering, $this->_ordering_types["$row_type"])) ) {
  525. return 'ORDER BY '. $this->_ordering_types["$row_type"]["$ordering"];
  526. } else {
  527. return null;
  528. }
  529. }// /->_order_by_clause()
  530.  
  531.  
  532. }// /class: EngCIS
  533.  
  534. ?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 121
Reputation: Auzzie is an unknown quantity at this point 
Solved Threads: 16
Auzzie Auzzie is offline Offline
Junior Poster

Re: Fatal error: require once

 
0
  #2
Feb 21st, 2008
unless i am totally mistaken it looks like the include file is missing
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: Fatal error: require once

 
0
  #3
Feb 21st, 2008
dami, you are getting this error because DOC__ROOT is an undefined constant. This was also happening in the code you sent me.

Try changing the required() calls from this:

require_once(DOC__ROOT . '/library/classes/class_dao.php');

to this:

require_once($_SERVER['DOCUMENT_ROOT'] . '/library/classes/class_dao.php');

If this doesn't work, then your DocumentRoot path has not been set.
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Fatal error: require once

 
0
  #4
Feb 22nd, 2008
hi richie, i changed the require_once to the one you said i should do but i got this error message


Notice: Only variable references should be returned by reference in C:\xampp\htdocs\capat\library\classes\class_engcis.php on line 9

Warning: require_once(C:/xampp/htdocs/library/classes/class_dao.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\capat\library\classes\class_engcis.php on line 18

Fatal error: require_once() [function.require]: Failed opening required 'C:/xampp/htdocs/library/classes/class_dao.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\capat\library\classes\class_engcis.php on line 18
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: Fatal error: require once

 
0
  #5
Feb 22nd, 2008
Hi dami,

Make sure those files exist and if they do, then they should be in those folders for them to be required.
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Fatal error: require once

 
0
  #6
Feb 22nd, 2008
hi richie,
those files exist and they are in the same folder. I will put the code of that file for you to look at. It's stil giving me that error message.

class_dao.php

  1. <?php
  2. /**
  3.  *
  4.  * Class : DAO
  5.  *
  6.  * This data access object is designed for MySQL only
  7.  *
  8.  *
  9.  * Updates:
  10.  * 18-07-2007 : improved ->_throw_error() code
  11.  * 13-07-2005 : added ->build_set() method - returns a string containing an SQL set
  12.  * 12-07-2005 : added ->get_num_cols() method - returns the number of column names
  13.  * 12-07-2005 : added ->get_cols() method - returns an array of column names
  14.  * 16-06-2005 : fixed a bug when using NULL values in do_insert/do_update
  15.  * 14-06-2005 : added $new_link parameter to ->open() method
  16.  * 13-06-2005 : added ->do_insert_multi() method for adding multiple rows in one statement
  17.  * 09-06-2005 : fixed potential insert-id bug
  18.  * 15-10-2004 : new ->fetch_assoc() method - gets the query as an associative array
  19.  * of the form: array ( row1.field1 => row1.field2, ... )
  20.  * 31-09-2004 : Fixed multi-database usage (stops connection clashing)
  21.  *
  22.  */
  23.  
  24.  
  25. class DAO {
  26. // Public Vars
  27.  
  28. // Private Vars
  29. private $_host = 'localhost'; // DB Connection info
  30. private $_user = '';
  31. private $_password = '';
  32. private $_database = 'pa';
  33. private $_persistent = false;
  34.  
  35. private $_conn = null; // DB Connection object
  36.  
  37. private $_result_set = null; // Contains the result set (temporarily)
  38. private $_result_cols = null; // Array of columns for the result set
  39.  
  40. private $_last_sql = null; // Last query run
  41. private $_result = null; // Query results, as array of row objects
  42.  
  43. private $_output_type = 'ARRAY_A'; // 'ARRAY_A': Associative Array : $results[row]['field']
  44. // 'ARRAY_N': Numeric Array : $results[row][col]
  45. // 'ARRAY_B': Assoc + Numeric Array : use $results[row]['field'] or $results[row][col]
  46.  
  47. private $_output_type_int = MYSQL_ASSOC; // MYSQL_ASSOC, MYSQL_BOTH, MYSQL_NUM
  48.  
  49. private $_insert_id = null; // Last inserted id (on auto-increment columns)
  50.  
  51. private $_num_cols = null;
  52. private $_num_rows = null;
  53. private $_num_affected = null;
  54.  
  55. private $_debug = false; // debug mode (default: off)
  56. private $_last_error = null;
  57.  
  58.  
  59. /**
  60. * CONSTRUCTOR
  61.   * Set database connection strings
  62.   * @param string $host
  63.   * @param string $user
  64.   * @param string $password
  65.   * @param string $database
  66.   * @param boolean $persistent
  67. */
  68. function DAO($host, $user, $password, $database, $persistent = false) {
  69. $this->_host = $host;
  70. $this->_user = $user;
  71. $this->_password = $password;
  72. $this->_database = $database;
  73. $this->_persistent = $persistent;
  74. } // /DAO()
  75.  
  76.  
  77. /*
  78. * ================================================================================
  79. * Public Methods
  80. * ================================================================================
  81. */
  82.  
  83.  
  84. /**
  85. * Open database connection
  86. * @param boolean $new_link block reusing an existing database connection when the same server/username/password are used
  87. * @return boolean
  88. */
  89. function open($new_link = true) {
  90. if (is_null($this->_conn)) {
  91. if ($this->_persistent) {
  92. $func = 'mysql_pconnect';
  93. } else {
  94. $func = 'mysql_connect';
  95. }
  96.  
  97. if ($this->_debug) {
  98. $this->_conn = @$func($this->_host, $this->_user, $this->_password, $new_link) or $this->_throw_error('Connecting to server');
  99. @mysql_select_db($this->_database, $this->_conn) or $this->_throw_error('Selecting Database');
  100. } else {
  101. $this->_conn = @$func($this->_host, $this->_user, $this->_password, $new_link);
  102. if(@!mysql_select_db($this->_database, $this->_conn)) {
  103. return false;
  104. }
  105. }
  106. }
  107. return true;
  108. } // /->open()
  109.  
  110. /**
  111.  * Close database connection
  112.  * @return object
  113.  */
  114. function close() {
  115. $this->flush();
  116. return ( @mysql_close($this->_conn) );
  117. } // /->close()
  118.  
  119.  
  120. /**
  121. * Clear results and reset result vars
  122. */
  123. function flush() {
  124. $this->_result = null;
  125. $this->_num_rows = null;
  126. $this->_num_affected = null;
  127. $this->_insert_id = null;
  128. } // /->flush()
  129.  
  130.  
  131. /**
  132. * Execute the SQL query, and ignore results (ie, not a SELECT)
  133. * Sets affected rows (ie could be DELETE/INSERT/REPLACE/UPDATE)
  134. * Sets inserted id if query is INSERT/REPLACE (checks first word of query)
  135. * @param string $sql
  136. * @return boolean
  137. */
  138. function execute($sql) {
  139. $this->flush();
  140. $this->open();
  141. $this->_last_sql = trim( $sql ); // Save query
  142.  
  143. if ($this->_debug) {
  144. $this->_result_set = mysql_query($sql, $this->_conn) or $this->_throw_error('Executing SQL');
  145. } else {
  146. $this->_result_set = @mysql_query($sql, $this->_conn);
  147. }
  148.  
  149. if ($this->_result_set) {
  150. $this->_num_affected = mysql_affected_rows($this->_conn);
  151.  
  152. if ( preg_match("/^\\s*(insert|replace) /i", $sql) ) {
  153. $this->_insert_id = mysql_insert_id($this->_conn);
  154. }
  155.  
  156. if ($this->_num_affected) {
  157. return true;
  158. } else {
  159. return false;
  160. }
  161. } else {
  162. return false;
  163. }
  164. }// /->execute()
  165.  
  166.  
  167. /**
  168. * Get results of the given query
  169. * @param string $sql
  170. * @return object
  171. */
  172. function fetch($sql = null) {
  173. // If there is an SQL query, get its results instead..
  174. if ( $sql ) { $this->_process_query($sql); }
  175.  
  176. return $this->_result;
  177. } // /->fetch()
  178.  
  179.  
  180. /**
  181. * Get a single row (of the given query or cache)
  182. * Row indexes are 0-based
  183. * @param string $sql
  184. * @param integer $y
  185. * @return object
  186. */
  187. function fetch_row($sql = null, $y = 0) {
  188. // If there is an SQL query, get its results instead..
  189. if ( $sql ) { $this->_process_query($sql); }
  190. return (isset($this->_result)) ? $this->_result[$y] : null;
  191. } // /->fetch_row()
  192.  
  193.  
  194. /**
  195. * Get a single column as a numeric array
  196. * column indexes are 0-based
  197. * @param string $sql
  198. * @param integer $x
  199. * @return array
  200. */
  201. function fetch_col($sql = null, $x = 0) {
  202. // If there is an SQL query, get its results instead..
  203. if ( $sql ) { $this->_process_query($sql); }
  204.  
  205. $new_array = null;
  206.  
  207. // Extract the column value
  208. if ($this->_num_rows>0) {
  209. for ( $i=0; $i<$this->_num_rows; $i++ ) {
  210. $new_array[$i] = $this->fetch_value(null,$x,$i);
  211. }
  212. }
  213. return $new_array;
  214. } // /->fetch_col()
  215.  
  216.  
  217. /**
  218. * Get a single value from the result set
  219.   * column/row indexes are 0-based
  220. * An empty string ('') or no value, will return null
  221. * @param string $sql
  222. * @param integer $x
  223. * @param integer $y
  224. * @return integer
  225. */
  226. function fetch_value($sql = null, $x = 0, $y = 0) {
  227. // If there is an SQL query, get its results instead..
  228. if ( $sql ) { $this->_process_query($sql); }
  229.  
  230. // Extract value using x,y vals
  231. if ( $this->_result[$y] ) {
  232. $values = array_values($this->_result[$y]);
  233. }
  234. // If there is a value return it, else return null
  235. return ( isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null;
  236. } // /->fetch_value()
  237.  
  238.  
  239. /**
  240. * Get an associative array ( field1-value => field2-value ) from the result set
  241. * If you retrieve more than 2 fields, you will get an associative array of row-arrays
  242. * e.g. field1-value => array ( field2 => field2-value, field3 => field3-value, ... ), ...
  243. * @param string $sql
  244. * @return array
  245. */
  246. function fetch_assoc($sql = null) {
  247. // Need to be in Numeric+Assoc Array mode, so set it
  248. $original_output_mode = $this->get_output_mode();
  249. $this->set_output($output = 'ARRAY_B');
  250.  
  251. // Fetch the new result set
  252. $this->_process_query($sql);
  253.  
  254. // Reset mode to what it was before
  255. $this->set_output($original_output_mode);
  256.  
  257. $new_array = null;
  258.  
  259. if ($this->_num_rows>0) {
  260. if ($this->get_num_cols()==2) {
  261. // Convert rows to simple associative array
  262. for ( $i=0; $i<$this->_num_rows; $i++ ) {
  263. $new_array["{$this->_result[$i][0]}"] = $this->_result[$i][1];
  264. }
  265. } else {
  266. // Convert rows to associative array of arrays
  267. for ( $i=0; $i<$this->_num_rows; $i++ ) {
  268. $row_array = null;
  269. for ( $j=1; $j<$this->_num_cols; $j++ ) {
  270. $row_array[$this->_result_cols["$j"]] = $this->_result[$i][$j];
  271. }
  272. $new_array["{$this->_result[$i][0]}"] = $row_array;
  273. }
  274. }
  275. }
  276. return $new_array;
  277. }// /->fetch_assoc()
  278.  
  279.  
  280. /**
  281. * Execute the insert query in $sql, using the fields in $fields
  282. * auto-slashes the given fields
  283. * @param string $sql string of the form 'INSERT INTO tbl_name ({fields}) VALUES ({values}) '
  284. * @param array $fields array ( fieldname1 => ???, fieldname2 => ???, ... )
  285. */
  286. function do_insert($sql, $fields) {
  287. $fields_str = implode(',', (array) array_keys($fields) );
  288.  
  289. $values = array();
  290. foreach ($fields as $k => $v) {
  291. $values[] = $this->_prepare_field_value($v);
  292. }
  293. $values_str = implode(',',$values);
  294.  
  295. $sql = str_replace('{fields}',$fields_str,$sql);
  296. $sql = str_replace('{values}',$values_str,$sql);
  297. return $this->execute($sql);
  298. } // /->do_insert()
  299.  
  300.  
  301. /**
  302. * Execute the insert query in $sql, using multiple VALUES statements as given in $fields
  303. * Auto-slashes the given fields
  304. *
  305. * NOTE : Unlike ->do_insert, the $fields array is an array[0..n] of assoc-arrays
  306. * NOTE : Only the last insert-id will be available from ->get_insert_id() following execution
  307. *
  308. * @param string $sql of the form, 'INSERT INTO tbl_name ({fields}) VALUES {values}
  309. * @param array $fields array[0..n] of array ( fieldname1 -> ???, fieldname2 => ???, ... )
  310. * @return object
  311. */
  312. function do_insert_multi($sql, $fields) {
  313. if (is_array($fields)) {
  314. $fields_str = implode(',', array_keys($fields[0]) );
  315.  
  316. $value_row = null;
  317.  
  318. foreach ($fields as $i => $row) {
  319. $value_row["$i"] = array ();
  320. foreach($row as $k => $v) {
  321. $value_row["$i"][] = $this->_prepare_field_value($v);
  322. }
  323. $value_row["$i"] = '('. implode(',',$value_row["$i"]) .')';
  324. }
  325. $values_str = implode(',',$value_row);
  326.  
  327. $sql = str_replace('{fields}',$fields_str,$sql);
  328. $sql = str_replace('{values}',$values_str,$sql);
  329.  
  330. return $this->execute($sql);
  331. } else {
  332. return null;
  333. }
  334. }// /->do_insert_multi()
  335.  
  336.  
  337. /**
  338. * Execute the update query in $sql, setting the fields in $fields
  339. * Auto-slashes the given fields
  340. * @param string $sql sql query of the form 'UPDATE tbl_name SET {fields} WHERE xxx=yyy'
  341. * @param array $fields of fields and values to set - of the form array ( fieldname1 => ???, fieldname2 => ???, ... )
  342. * @return mixed
  343. */
  344. function do_update($sql, $fields) {
  345. $set_str = '';
  346. $fields_count = count($fields);
  347. $i=1;
  348.  
  349. foreach ($fields AS $k=>$v) {
  350. $set_str .= " $k=". $this->_prepare_field_value($v);
  351. if ($i<$fields_count) { $set_str .= ','; }
  352. ++$i;
  353. }
  354.  
  355. $sql = str_replace('{fields}',$set_str,$sql);
  356. return $this->execute($sql);
  357. } // /->do_update()
  358.  
  359.  
  360. /**
  361. * Builds filter clause of the form (aaa='bbb' OR aaa='ccc' OR aaa='ddd' ... )
  362. *
  363. * @param string $field_name the field name being checked (aaa in example above)
  364. * @param array/value $filter_values the values to compare against.
  365. * @param string $logical_operator the operator to use to concatenate the filters (AND, OR, XOR)
  366. * @return string
  367. */
  368. function build_filter($field_name, $filter_values, $logical_operator = 'OR') {
  369. $filter_values = (array) $filter_values; // cast values to array (in case it was only passed one)
  370.  
  371. $filter_clause = '(';
  372. $w_count = count($filter_values);
  373. $i = 1;
  374. foreach($filter_values as $k => $v) {
  375. $v = $this->escape_str($v);
  376. $filter_clause .= "$field_name=". $this->_prepare_field_value($v);
  377. if ($i<$w_count) { $filter_clause .= " $logical_operator "; }
  378. $i++;
  379. }
  380. $filter_clause .= ')';
  381.  
  382. return $filter_clause;
  383. }// ->build_filter()
  384.  
  385.  
  386. /**
  387. * Builds an SQL set of the form ('aaa','bbb','ccc') for use with IN operators
  388. *
  389. * @param array/value $value_array array of values to include in the set
  390. * @return string
  391. */
  392. function build_set($value_array) {
  393. $value_array = array_map('addslashes',(array) $value_array);
  394. return '(\''. implode('\',\'',$value_array) .'\')';
  395. }// /->build_set()
  396.  
  397.  
  398. /*
  399. * --------------------------------------------------------------------------------
  400. * Accessor Methods
  401. * --------------------------------------------------------------------------------
  402. */
  403.  
  404. // GET_xxx functions
  405.  
  406. /**
  407.   * Return an array of columns names from the last query
  408.   * @return boolean
  409.   */
  410. function get_cols() { return (is_array($this->_result_cols)) ? $this->_result_cols : null ; }
  411.  
  412.  
  413. /**
  414.   * Return the number of columns from the last query
  415.   * @return integer
  416.   */
  417. function get_num_cols() { return $this->_num_cols; }
  418.  
  419.  
  420. /**
  421.   * Return the number of rows from the last query
  422.   * @return integer
  423.   */
  424. function get_num_rows() { return $this->_num_rows; }
  425.  
  426.  
  427. /**
  428.   * Return the number of affected rows from the last query (insert/replace/update)
  429.   * @return integer
  430.   */
  431. function get_num_affected() { return $this->_num_affected; }
  432.  
  433.  
  434. /**
  435.   * Return last inserted id (for auto-increment columns)
  436.   * @return integer
  437.   */
  438. function get_insert_id() { return $this->_insert_id; }
  439.  
  440.  
  441. /**
  442.   * Return last run query
  443.   * @return string
  444.   */
  445. function get_last_sql() { return $this->_last_sql; }
  446.  
  447.  
  448. /**
  449.  * Get last mysql error
  450.  */
  451. function get_last_error() { mysql_error($this->_conn); }
  452.  
  453.  
  454. /**
  455. * Get output mode
  456. * @return mixed
  457. */
  458. function get_output_mode() { return $this->_output_type; }
  459.  
  460.  
  461. /*
  462. * --------------------------------------------------------------------------------
  463. * SET_xxx functions
  464. * --------------------------------------------------------------------------------
  465. */
  466.  
  467. /**
  468. * Set debug mode
  469. * When in debug mode, detailed error reports are echoed
  470. * @param boolean
  471. */
  472. function set_debug($on) {
  473. $this->_debug = $on;
  474. }
  475.  
  476.  
  477. /**
  478. * Set default output mode for results array
  479. * @param string $output
  480. * @return boolean
  481. */
  482. function set_output($output = 'ARRAY_A') {
  483. switch ($output) {
  484. case 'ARRAY_A' :
  485. $this->_output_type_int = MYSQL_ASSOC;
  486. $this->_output_type = $output;
  487. return true;
  488. break;
  489. // ----------------------------------------
  490. case 'ARRAY_B' :
  491. $this->_output_type_int = MYSQL_BOTH;
  492. $this->_output_type = $output;
  493. return true;
  494. break;
  495. // ----------------------------------------
  496. case 'ARRAY_N' :
  497. $this->_output_type_int = MYSQL_NUM;
  498. $this->_output_type = $output;
  499. return true;
  500. break;
  501. // ----------------------------------------
  502. default :
  503. return false;
  504. break;
  505. }
  506. }// /->set_output()
  507.  
  508.  
  509. /**
  510.   * Escape character string
  511.   * @param string $str
  512.   * @return string
  513.   */
  514. function escape_str($str) { return mysql_escape_string(stripslashes($str)); }
  515.  
  516.  
  517. /*
  518. * ================================================================================
  519. * Private Methods
  520. * ================================================================================
  521. */
  522.  
  523.  
  524. /**
  525. * Execute the SQL and collect the result set
  526. * @param string $sql
  527. * @return boolean
  528. */
  529. function _process_query($sql) {
  530. $this->flush();
  531. $this->open();
  532. $this->_last_sql = trim( $sql ); // Save query
  533.  
  534. if ($this->_debug) {
  535. $this->_result_set = mysql_query($sql, $this->_conn) or $this->_throw_error('Querying database');
  536. } else {
  537. $this->_result_set = @mysql_query($sql, $this->_conn);
  538. }
  539.  
  540. // If got a result set..
  541. if ($this->_result_set) {
  542.  
  543. // number of columns returned
  544. $this->_num_cols = mysql_num_fields($this->_result_set);
  545.  
  546. // Store column names as an array
  547. $i=0;
  548. $this->_result_cols = array();
  549. while ($i < $this->_num_cols) {
  550. $field = @mysql_fetch_field($this->_result_set,$i);
  551. $this->_result_cols[] = $field->name;
  552. $i++;
  553. }
  554.  
  555. // Store the results as an array of row objects
  556. while ( $row = @mysql_fetch_array($this->_result_set,$this->_output_type_int) ) {
  557. $this->_result[] = $row;
  558. }
  559.  
  560. // number of rows returned
  561. $this->_num_rows = count($this->_result);
  562.  
  563. // Free the actual result set
  564. @mysql_free_result($this->_result_set);
  565.  
  566. // If there were results.. return true
  567. return ($this->_num_rows>=1);
  568. } else {
  569. $this->_num_cols = 0;
  570. $this->_num_rows = 0;
  571. $this->_result_cols = null;
  572. return false;
  573. }
  574. } // /->process_query()
  575.  
  576. /**
  577. * function to capture the thrown error and out put to the screen
  578. * @param string $err_msg
  579. * @return boolean
  580. */
  581. function _throw_error($err_msg) {
  582. if ($this->_conn) {
  583. die("<hr />DATABASE ERROR<hr />$err_msg :: ". mysql_error($this->_conn) .'<hr />'. $this->get_last_sql().'<hr />');
  584. } else {
  585. die("<hr />DATABASE ERROR<hr />$err_msg :: &lt;NO SERVER&gt;<hr />". $this->get_last_sql().'<hr />');
  586. }
  587. return false;
  588. }// /->_throw_error()
  589.  
  590.  
  591. /**
  592. * Prepare a value for putting into the database
  593. * Escapes special characters, checks for NULL, and puts in quotes as necessary
  594. *
  595. * @param integer $value value to prepare
  596. *
  597. * @return string en-quoted value, ready for insertion into a database (of the form 'value' or NULL)
  598. */
  599. function _prepare_field_value($value) {
  600. // NULL values don't need quotes, so if it's null, just return a string containing NULL
  601. // Else, return an escaped string containing the value enclosed in quotes
  602. return (is_null($value)) ? 'NULL' : '\''. $this->escape_str($value) .'\'';
  603. }// /->_prepare_field_value()
  604.  
  605.  
  606. } // /class: DAO
  607.  
  608. ?>

I never had all these errors before, i don't why i'm having them now
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Fatal error: require once

 
0
  #7
Feb 22nd, 2008
right what i have done now is to disable the error reporting and now i don't have that showing all over my screen but now i get this error message

?>
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\capat\include\classes\class_ui1.php:2) in C:\xampp\htdocs\capat\tutors\forms\create\class_wizardstep_2.php on line 70

what does this mean
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: Fatal error: require once

 
0
  #8
Feb 22nd, 2008
Send me all of you code dami, I'll have a look
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: dami06 is an unknown quantity at this point 
Solved Threads: 0
dami06 dami06 is offline Offline
Junior Poster in Training

Re: Fatal error: require once

 
0
  #9
Feb 23rd, 2008
ok richie, im going to send the code to you now and let you know where the problem is..Please reply to me soon with solution as i need to hand this in by tuesday..thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 158
Reputation: richie513 is an unknown quantity at this point 
Solved Threads: 11
richie513's Avatar
richie513 richie513 is offline Offline
Junior Poster

Re: Fatal error: require once

 
0
  #10
Feb 23rd, 2008
As soon as I recieve I will have a look
Technology is just a tool. In terms of getting the kids working together and motivating them, the teacher is the most important.
richie513
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC