Not getting information from the database

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

Not getting information from the database

 
0
  #1
Feb 28th, 2008
Hi Guys,
I'm trying to create a webpage where it's meant to get some information which i put in the database and then show in the webpage but it's not getting the information. Could you please take a look at my code and tell me if there is a problem somewhere.. Thanks

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

Re: Not getting information from the database

 
0
  #2
Feb 28th, 2008
Please post relevant code only. IE., any code that has changed since the last time it worked. Posting ~1k lines of code then saying "What's wrong" doesn't help. Also, if you are using a class that has been worked on as much as this then the problem most likely lies in your query.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
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: Not getting information from the database

 
0
  #3
Feb 28th, 2008
ok what about this code, i just cut the old one down to this
  1. #
  2. class DAO {
  3. #
  4. // Public Vars
  5. #
  6.  
  7. #
  8. // Private Vars
  9. #
  10. private $_host = ''; // DB Connection info
  11. #
  12. private $_user = '';
  13. #
  14. private $_password = '';
  15. #
  16. private $_database = '';
  17. #
  18. private $_persistent = false;
  19. #
  20.  
  21. #
  22. private $_conn = null; // DB Connection object
  23. #
  24.  
  25. #
  26. private $_result_set = null; // Contains the result set (temporarily)
  27. #
  28. private $_result_cols = null; // Array of columns for the result set
  29. #
  30.  
  31. #
  32. private $_last_sql = null; // Last query run
  33. #
  34. private $_result = null; // Query results, as array of row objects
  35. #
  36.  
  37. #
  38. private $_output_type = 'ARRAY_A'; // 'ARRAY_A': Associative Array : $results[row]['field']
  39. #
  40. // 'ARRAY_N': Numeric Array : $results[row][col]
  41. #
  42. // 'ARRAY_B': Assoc + Numeric Array : use $results[row]['field'] or $results[row][col]
  43. #
  44.  
  45. #
  46. private $_output_type_int = MYSQL_ASSOC; // MYSQL_ASSOC, MYSQL_BOTH, MYSQL_NUM
  47. #
  48.  
  49. #
  50. private $_insert_id = null; // Last inserted id (on auto-increment columns)
  51. #
  52.  
  53. #
  54. private $_num_cols = null;
  55. #
  56. private $_num_rows = null;
  57. #
  58. private $_num_affected = null;
  59. #
  60.  
  61. #
  62. private $_debug = false; // debug mode (default: off)
  63. #
  64. private $_last_error = null;
  65. #
  66.  
  67. #
  68.  
  69. #
  70. /**
  71. #
  72. * CONSTRUCTOR
  73. #
  74.   * Set database connection strings
  75. #
  76.   * @param string $host
  77. #
  78.   * @param string $user
  79. #
  80.   * @param string $password
  81. #
  82.   * @param string $database
  83. #
  84.   * @param boolean $persistent
  85. #
  86. */
  87. #
  88. function DAO($host, $user, $password, $database, $persistent = false) {
  89. #
  90. $this->_host = $host;
  91. #
  92. $this->_user = $user;
  93. #
  94. $this->_password = $password;
  95. #
  96. $this->_database = $database;
  97. #
  98. $this->_persistent = $persistent;
  99. #
  100. } // /DAO()
  101. #
  102.  
  103. #
  104.  
  105. #
  106. /*
  107. #
  108. * ================================================================================
  109. #
  110. * Public Methods
  111. #
  112. * ================================================================================
  113. #
  114. */
  115. #
  116.  
  117. #
  118.  
  119. #
  120. /**
  121. #
  122. * Open database connection
  123. #
  124. * @param boolean $new_link block reusing an existing database connection when the same server/username/password are used
  125. #
  126. * @return boolean
  127. #
  128. */
  129. #
  130. function open($new_link = true) {
  131. #
  132. if (is_null($this->_conn)) {
  133. #
  134. if ($this->_persistent) {
  135. #
  136. $func = 'mysql_pconnect';
  137. #
  138. } else {
  139. #
  140. $func = 'mysql_connect';
  141. #
  142. }
  143. #
  144.  
  145. #
  146. if ($this->_debug) {
  147. #
  148. $this->_conn = @$func($this->_host, $this->_user, $this->_password, $new_link) or $this->_throw_error('Connecting to server');
  149. #
  150. @mysql_select_db($this->_database, $this->_conn) or $this->_throw_error('Selecting Database');
  151. #
  152. } else {
  153. #
  154. $this->_conn = @$func($this->_host, $this->_user, $this->_password, $new_link);
  155. #
  156. if(@!mysql_select_db($this->_database, $this->_conn)) {
  157. #
  158. return false;
  159. #
  160. }
  161. #
  162. }
  163. #
  164. }
  165. #
  166. return true;
  167. #
  168. } // /->open()
  169. #
  170.  
  171. #
  172. /**
  173. #
  174.  * Close database connection
  175. #
  176.  * @return object
  177. #
  178.  */
  179. #
  180. function close() {
  181. #
  182. $this->flush();
  183. #
  184. return ( @mysql_close($this->_conn) );
  185. #
  186. } // /->close()
  187. #
  188.  
  189. #
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Not getting information from the database

 
0
  #4
Feb 28th, 2008
Take all of the @ out from in front of the function calls, that is suppressing the errors. You'll be able to see the errors after you remove them.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
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: Not getting information from the database

 
0
  #5
Feb 28th, 2008
Hi dami,

You need to set your connection credentials.

change these lines:

private $_host = ''; // DB Connection info
#
private $_user = '';
#
private $_password = '';
#
private $_database = '';
#

to this:

private $_host = 'localhost';
#
private $_user = 'Your MySQL Username';
#
private $_password = 'Your MySQL Password';
#
private $_database = 'The name of the database you are trying to connect to';
#

Without this information, PHP can't connect to the database
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: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Not getting information from the database

 
0
  #6
Feb 28th, 2008
Richie, those lines of code are from a class. They are most likely being initialized in the constructor.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
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: Not getting information from the database

 
0
  #7
Feb 28th, 2008
i did put all the database information into it but nothing changed. I will try and remove the @ and see if anything turn up..
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: Not getting information from the database

 
0
  #8
Feb 28th, 2008
I have done this but i didn't get any error message

Originally Posted by ShawnCplus View Post
Take all of the @ out from in front of the function calls, that is suppressing the errors. You'll be able to see the errors after you remove them.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Not getting information from the database

 
0
  #9
Feb 28th, 2008
um,
  1. $this->_host = $host; $this->_user = $user; $this->_password = $password; $this->_database = $database; $this->_persistent = $persistent;

Up top you have
  1. private $_user = ''; private $_password = ''; private $_database = ''; private $_persistent = false;

I'm assuming that your database information isn't even being called at all in any of your functions because you have used $_ in your declaration of the variables, but are trying to call it a different way later on?

Of course, this could just be something that I am not familiar with.
Sage
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: Not getting information from the database

 
0
  #10
Feb 28th, 2008
No, I'm not trying to call it in a different way. I also think that the database isn't being called in any function that's why it isn't retrieving the information i put in the database
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