Welcome Guest, Not a member yet? Register   Sign In
how to hide A Database Error Occurred.....................
#1

[eluser]noname525[/eluser]
vv
#2

[eluser]InsiteFX[/eluser]
Why not fix the Error!
#3

[eluser]noname525[/eluser]
vv
#4

[eluser]InsiteFX[/eluser]
you check the table first to see if that value exists if it does then you skip the process and return. Else if it does not exist then add it to the table...

#5

[eluser]noname525[/eluser]
vv
#6

[eluser]John Murowaniecki[/eluser]
If you're using MySQL perhaps this will help you a little bit..

Code:
public function exist_country_table()
{
  $query = $this->db->query("show tables like 'country'");
  return $query->num_rows() > 0
   ? TRUE
   : $this->db->query("CREATE TABLE `country` (
    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `name` VARCHAR( 128 ) NOT NULL
   ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;");
}
#

public function save_country($country = FALSE)
{
  if ($this->exist_country_table());
  #
  $query = ( ! $this->verify_country())
   ? $this->db->query("INSERT INTO `country` (`name`) VALUES (?)", array($country ? $country : $this->input->post('country')))
   : FALSE;
  var_dump(array($query ? 'Country inserted' : 'An error occurs, perhaps you already have this country saved'));
}
#

public function verify_country($country = FALSE)
{
  if ($this->exist_country_table());
  #
  $country = $country ? $country : $this->input->post('country');
  $query   = $this->db->query("SELECT id FROM country WHERE name LIKE '%$country%'");
  return $query->num_rows() > 0 ? TRUE : FALSE;
}
#

..But I recomend you to first learn PHP/SQL, after how CodeIgniter works and after all how DataMapper can turn your miserable life into a paradise on earth.

;-)

P.S.: make the machine work for you, not vice versa.
#7

[eluser]toopay[/eluser]
Simply set (within config/database.php)
Code:
$db['default']['db_debug'] = TRUE;
into FALSE. Thus, every query() execution will returning FALSE if it fail, then you could handle the error yourself. But i agree with those black cat Smile, fix that error.

The error is in your SQL statement, not by user input, which in this case, CI try to fails gracefully, instead outputing 500 internal server error, which probably will be more difficult to you to debug.
#8

[eluser]noname525[/eluser]
vv
#9

[eluser]John Murowaniecki[/eluser]
Dude: rewrite your post. It's very hard to know what you have and what want. I can't understand what did you mean.




Theme © iAndrew 2016 - Forum software by © MyBB