Welcome Guest, Not a member yet? Register   Sign In
Create a custom MySQL connection error
#2

I answered a lot of my questions above, just to come up with more questions :-D hah

Heres the code thus far, (obviously in dev, hence all the die() statements)

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
App_hooks
{
    public function 
pre_system_check_mysql()
    {
        require(
APPPATH.'config/database.php');

        
$creds $db[$active_group];

        if( ! 
$conn = @mysqli_connect($creds['hostname'], $creds['username'], $creds['password']))
        {
            die(
'Cant connect');
        }

        if (
mysqli_connect_errno())
        {
            die(
"Failed to connect to MySQL: " mysqli_connect_error());
        }

        if( ! @
mysqli_select_db($conn$creds['database']))
        {
            die(
"Cant select DB ({$active_group})");
        }

        die(
'OK');
    }


This works, but obviously it only works with the mysqli driver. This application will actually be distributed as Open Source, so its possible that whoever uses it, uses a different driver.

I know the DB_Driver library has methods to accommodate for this, but obviously it isn't loaded yet.

What would you recommend I do? Or do I really even have any other option? (Short of mimicking the db_connect and db_select methods in the DB_Driver manually)

Thanks!
Reply


Messages In This Thread
RE: Create a custom MySQL connection error - by jLinux - 10-19-2015, 09:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB