Created
September 1, 2013 00:22
-
-
Save phpfiddle/6401514 to your computer and use it in GitHub Desktop.
Testing pdo
This file contains hidden or 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 | |
* @copyright Copyright (c) 2012 - 2013, PhpFiddle.org | |
* @link http://phpfiddle.org | |
* @since 2012 | |
*/ | |
require_once "dBug!.php"; | |
$dsn = "mysql:host=localhost;dbname=xfiddlec_max;port=3306"; | |
$user_name = "xfiddlec_user"; | |
$pass_word = "public"; | |
$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(); | |
//for one-time query, this line is same with code from line 19 to 24 | |
//$result = $connect->query($sql); | |
if (($status) && ($result->rowCount() > 0)) | |
{ | |
$results = array(); | |
//convert query result into an associative array | |
while ($row = $result->fetchObject()) | |
{ | |
$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