Tag : database

Building an API

Imagine if you could take an existing sql database and turn it into a RESTful JSON based web service, then access the data via the API from perhaps an android application or an other third party application.  I wondered about this and then I stumbled upon PHP DATA SERVICES (PHPDS) built by Chatura Dilan  PHPDS

How to create a new database with PHP & PDO

Creating a new databse with PHP and PDO : <?php // Hosting details $host=”localhost”; $root=”root”; $root_password=”rootpass”; // New database user, password & database name $user=’newuser’; $pass=’newpass’; $db=”newdb”; // Create database connnection try { $dbh = new PDO(“mysql:host=$host”, $root, $root_password); // Exectute $dbh->exec(“CREATE DATABASE `$db`; CREATE USER ‘$user’@’localhost’ IDENTIFIED BY ‘$pass’; GRANT ALL ON `$db`.* TO

PDO code to show all databases

Showing a list of all the databases using PHP and PDO. <?php $user = ‘root’; $pass = ‘password’; $server = ‘localhost’; $dbh = new PDO( “mysql:host=$server”, $user, $pass ); $dbs = $dbh->query( ‘SHOW DATABASES’ ); while( ( $db = $dbs->fetchColumn( 0 ) ) !== false ) { echo $db.’ ‘; } ?> Will out a