Posts

Showing posts from January, 2019

MySql Connection

<?php $servername =  "localhost" ; $username =  "root" ; $password =  "data base password" ; // Create database connection $con =  new  mysqli($servername, $username, $password); // Check database connection if  ($con->connect_error) {      die ( "Connection failed: "  . $con->connect_error); }   echo   "Connected successfully" ; ?> create a database db-restapi ---- And create a table CREATE TABLE IF NOT EXISTS `categories` (    `id` int (11) NOT NULL AUTO_INCREMENT,    ` name ` varchar (256) NOT NULL ,    `description` text NOT NULL ,    `created` datetime NOT NULL ,    `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,    PRIMARY KEY (`id`) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ; Connect to database using PDO ----------------- <?php class Database{ ...