Created
May 31, 2017 02:03
-
-
Save phpfiddle/ece945bc9688ff645aebd69710295ba3 to your computer and use it in GitHub Desktop.
[ Posted by Don Stringham ] PDO initial 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 | |
/** | |
* PDO MySQL 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"; | |
$connect = new PDO($dsn, $user_name, $pass_word); | |
//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 data | |
//$sql = "SELECT * FROM books WHERE id <= 10"; | |
$result = $connect->prepare($sql); | |
//bind parameter(s) to variable(s) | |
//$result->bindParam( . . . ); | |
$status = $result->execute(); | |
//Next line is same with code from line 29 to 34 for one-time query | |
//$result = $connect->query($sql); | |
if (($status) && ($result->rowCount() > 0)) | |
{ | |
$results = array(); | |
//convert query result into an associative array | |
while ($row = $result->fetch(PDO::FETCH_ASSOC)) | |
{ | |
$results[] = $row; | |
} | |
//dump all data from associative array converted from query result | |
new dBug($results); | |
} | |
$connect = null; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment