MySQLi - Full example

<?php // Settings for database connection $db_host = 'localhost'; $db_user = 'user'; $db_password = 'password'; $db_database= 'database'; // Connect and check $db = new mysqli($db_host, $db_user, $db_password, $db_database); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } // Query database $query = <<<SQL SELECT * FROM `users` WHERE `active` = 1 SQL; if(!$result = $db->query($query)){ die('There was an error running the query [' . $db->error . ']'); } // Clean up the mess $result->free(); $db->close(); ?>
Example of how to connect to database and query it via MySQLi.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.