9three Posted April 19, 2009 Share Posted April 19, 2009 Hey, I'm having an issue. It's always returning "connected" whether the data base name is correct or not. public function connect() { $this->link = new mysqli($this->host, $this->username, $this->password, $this->dbname); if ($this->link->connect_error) { // Error returned true Throw New Exception($this->link->connect_error); } return $this->link; //No exception was thrown, return $this->link } This is the index: try { $mysqli = new mysql('localhost', 'root', '', 'cms2'); echo 'Connected'; } catch (Exception $e) { echo $e; } the database name is actually 'cms' not 'cms2'. But either way it prints "connected" If I do !$this->link->connect_error it returns an exception exception 'Exception' in C:\Users\9three\Desktop\Server\htdocs\library\mysqli.package.php:23 Stack trace: #0 C:\Users\9three\Desktop\Server\htdocs\library\mysqli.package.php(16): mysql->connect() #1 C:\Users\9three\Desktop\Server\htdocs\library\index.php(12): mysql->__construct('localhost', 'root', '', 'cms2') #2 {main} Again, whether I use 'cms' or 'cms2' it still throws this exception. Now I don't know why, the syntax looks correct in the class. I'm still learning to use MySQLi. Quote Link to comment https://forums.phpfreaks.com/topic/154705-mysqli-and-exceptions/ Share on other sites More sharing options...
Philip Posted April 19, 2009 Share Posted April 19, 2009 I think it's because if ($this->link->connect_error) will always be true try: if (!empty($this->link->connect_error)) Quote Link to comment https://forums.phpfreaks.com/topic/154705-mysqli-and-exceptions/#findComment-813503 Share on other sites More sharing options...
9three Posted April 19, 2009 Author Share Posted April 19, 2009 No it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/154705-mysqli-and-exceptions/#findComment-813507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.