connect() public method

Since the library is using lazy connection (it is not actually connecting to the database until the first query is executed), the object representing the connection to the MySQL server is not available at this time. If you need it, use the {@link get_link()} method. If you need the connection to the database to be made right away, set the connect argument to TRUE. create the database object $db = new Zebra_Database(); notice that we're not doing any error checking. errors will be shown in the debugging console $db->connect('host', 'username', 'password', 'database'); code goes here show the debugging console (if enabled) $db->show_debug_console();
public connect ( string $host, string $user, string $password, string $database, string $port = '', string $socket = '', boolean $connect = false ) : void
$host string The address of the MySQL server to connect to (i.e. localhost). Prepending host by p: opens a persistent connection. @param string $user The user name used for authentication when connecting to the MySQL server. @param string $password The password used for authentication when connecting to the MySQL server. @param string $database The database to be selected after the connection is established. @param string $port (Optional) The port number to attempt to connect to the MySQL server. Leave as empty string to use the default as returned by ini_get("mysqli.default_port"). @param string $socket (Optional) The socket or named pipe that should be used. Leave as empty string to use the default as returned by ini_get("mysqli.default_socket"). Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. How the connection is made to the MySQL database is determined by the host argument. @param boolean $connect (Optional) Setting this argument to TRUE will force the library to connect to the database right away instead of using a "lazy connection" where the actual connection to the database will be made when the first query is run. Default is FALSE. @return void
$user string
$password string
$database string
$port string
$socket string
$connect boolean
return void
Exemplo n.º 1
0
 public static function database()
 {
     require_once __DIR__ . '/Zebra_Database/Zebra_Database.php';
     $connection = new Zebra_Database();
     $connection->debug = true;
     $connection->connect('localhost', 'spalmer', 'Spalm04350', 'alpha');
     //$connection->connect('localhost','root','','alpha');
     $connection->set_charset();
     return $connection;
 }
Exemplo n.º 2
0
        <em>world</em></a> test database from MySQL's website.<br>
        Then, you must edit this file (example.php) and change the settings of <em>host</em>, <em>user name</em>, <em>password</em>
        and <em>database</em> to match your configuration.
    </p>

    <?php 
// THIS EXAMPLE IS VERY BRIEF!
// CHECK THE DOCUMENTATION TO SEE WHAT METHODS ARE AVAILABLE!
// include the wrapper class
require '../Zebra_Database.php';
// create a new database wrapper object
$db = new Zebra_Database();
// turn debugging on
$db->debug = true;
// connect to the MySQL server and select the database
$db->connect('', '', '', '');
$db->set_charset();
// let's work with a country
$country = 'Romania';
// get the country's code
$country_code = $db->dlookup('Code', 'country', 'Name = ?', array($country));
// get all the cities for the country code
$db->query('
            SELECT
                Name
            FROM
                city
            WHERE
                CountryCode = ?
            ORDER BY
                Name