Created
May 31, 2017 01:59
-
-
Save phpfiddle/cc04835631d1d24bf1d9c532abff8939 to your computer and use it in GitHub Desktop.
[ Posted by Don Stringham ] Mysqli introduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Mysqli initial code | |
* | |
* User permissions of database | |
* Create, Alter and Index table, Create view, and Select, Insert, Update, Delete table data | |
* | |
* @package PhpFiddle | |
* @link http://phpfiddle.org | |
* @since 2012 | |
*/ | |
require_once "dBug!.php"; | |
require "util/public_db_info.php"; | |
$short_connect = new mysqli($host_name, $user_name, $pass_word, $database_name, $port); | |
//get all tables in the database | |
$sql = "SHOW TABLES"; | |
//get column information from a table in the database | |
//$sql="SELECT COLUMN_KEY, COLUMN_NAME, COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME = 'books'"; | |
//SQL statement for a table in the database | |
// $sql = "SELECT * FROM books WHERE id <= 10"; | |
//result is boolean for query other than SELECT, SHOW, DESCRIBE and EXPLAIN | |
$result = $short_connect->query($sql); | |
if (($result) && ($result->num_rows > 0)) | |
{ | |
$results = array(); | |
//convert query result into an associative array | |
while ($row = $result->fetch_assoc()) | |
{ | |
$results[] = $row; | |
} | |
//dump all data from associative array converted from query result | |
new dBug($results); | |
$result->free(); | |
} | |
$short_connect->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment