Test a database conection without codeigniter throwing a fit, can it be done?

Posted by RobertWHurst on Stack Overflow See other posts from Stack Overflow or by RobertWHurst
Published on 2010-05-16T21:04:37Z Indexed on 2010/05/16 21:40 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

I'm just about finished my first release of automailer, a program I've been working on for a while now. I've just got to finish writing the installer. Its job is to rewrite the codigniter configs from templates. I've got the read/write stuff working, but I'd like to be able to test the server credentials given by the user without codingiter throwing a system error if they're wrong. Is there a function other than mysql_connect that I can use to test a connection that will return true or false and won't make codeigniter have a fit?

This is what I have

function _test_connection(){
    if(mysql_connect($_POST['host'], $_POST['username'], $_POST['password'], TRUE))
        return TRUE;
    else
        return FALSE;
}

Codigniter doesn't like this and throws a system error.

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

    <h4>A PHP Error was encountered</h4>

    <p>Severity: Warning</p>
    <p>Message:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Unknown MySQL server host 'x' (1)</p>
    <p>Filename: controllers/install.php</p>
    <p>Line Number: 57</p>

</div>

I'd rather not turn off error reporting.

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about php