MySQLi- I'm getting ready for that update! [PHP]

Status
Not open for further replies.

DaLightz

See ya'll in the afterlife.
May 19, 2012
1,136
262
Hello, just heard the news of MySQL not being used anymore in the new PHP update. So I am starting to get used to MySQLi now since i have never quite used it before.

So, here we go. This is just as new to me as it is to a 'noob' so please feel free to correct me if i have done something wrong.

Connect.
PHP:
<?php
// Connection bit here..
$connect = mysqli_connect('localhost', 'root', 'popmycherry', 'Habbodb');
 
// Check yo' self.
if (mysqli_connect_errno){
                  echo 'Connection error: %s\n', mysqli_connect_error());
                 exit();
}
?>

Something.php
PHP:
<?php
// Require the Mysqli class
require_once 'MySQLi.php';
//The query.
$new_query = mysqli_query("SELECT * FROM users WHERE username='. $something here .'");
?>

Please let me know if this is correct. I have a feeling it's not.
 

DaLightz

See ya'll in the afterlife.
May 19, 2012
1,136
262
If you are going to use MySQLi, then you should use OOP as Rasta stated.

Or you can use PDO :)
Ugg. You and that PDO.

I suppose i could do a configuration for Database Drivers. 
PHP:
<?php
    /*================================================================+\
    || # WambaPHP- An all around Component Content Management System. ||
    |+================================================================+|
    || # Copyright (C) 2012 CookieMonsta. All rights reserved.        ||
    || # http://www.devbest.com/user/CookieMonsta                    ||
    || # This was a scratch development. Love to devbest for support! ||
    |+================================================================+|
    || # WambaPHP is provided "as is" and comes without              ||
    || # warrenty of any kind. WambaPHP is free software!            ||
    || # License: GNU Public License 3.0                              ||
    || # http://opensource.org/licenses/gpl-license.php              ||
    \+================================================================*/
 
    /*
    *
    *  WambaPHP- MySQLi Class
    *
    */
 
    // #################################################################
    // Secure this file.
        if(!Defined('WambaPHP_Secure')) die ("Direct Access Denied");
     
    // #################################################################
    // Start the script.
        // Define the class.
            class MySQLi_Database
            {
                public function __construct()
            {
        // Fetch Configuration variables.
          Global $_CONFIG;
              $this->MySQLi_Hostname = $_CONFIG['MySQLi']['Hostname'];
              $this->MySQLi_Username = $_CONFIG['MySQLi']['Username'];
              $this->MySQLi_Password = $_CONFIG['MySQLi']['Password'];
              $this->MySQLi_Database = $_CONFIG['MySQLi']['Database'];
            }
            public function connect()
            {
            $this->MySQLi_Connect =
                    @mysqli_connect($this->MySQLi_Hostname, $this->MySQLi_Username, $this->MySQLi_Password, $this->MySQLi_Database);
 
        // Check the connection & close the conneciton.
                if (mysqli_connect_errno())
                {
                    printf("Connect failed: %s\n", mysqli_connect_error());
                    exit();
                }
            }
                public function disconnect()
        {
                @mysqli_close($this->MySQLi_Connect);
        }
        }
     
    // #################################################################
    // End...
?>

I win :)
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
MySQLi performs better, but PDO supports 12 different drivers. :D

And if you are going to make a script, why not make it open to all databases?

The performance between MySQLi and PDO is not that different :p

EDIT:

I'd change
PHP:
MySQLi_Hostname = $_CONFIG['MySQLi']

To something else, maybe

PHP:
Hostname = $_CONFIG['Hostname']


Having the MySQLi_ prefix is ugly :p
 

DaLightz

See ya'll in the afterlife.
May 19, 2012
1,136
262
MySQLi performs better, but PDO supports 12 different drivers. :D

And if you are going to make a script, why not make it open to all databases?

The performance between MySQLi and PDO is not that different :p

EDIT:

I'd change
PHP:
MySQLi_Hostname = $_CONFIG['MySQLi']

To something else, maybe

PHP:
Hostname = $_CONFIG['Hostname']


Having the MySQLi_ prefix is ugly :p
I'll fix that prefix.
I'd recommend using the OOP method.

Here's a tutorial if you need help:
Thanks. Nice brush up for me, just what i needed.
 
Status
Not open for further replies.

Users who are viewing this thread

Top