Translate To Preferred Language

Search Obioku's Thoughts

Please Read Today's Featured Post

Things I Would Like To Happen Soon

For all those who believe in speaking ideas into existence and prayer in the universe will return to a person.  I simply want to write a lis...


Use the button below to make one time or recurring donations to help generate income. Thank you very much for your generosity. Please continue to enjoy

HelloWorld Example in PHP (some bugs may occur)

// A simple web site in Cloud9 that runs through Apache
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console

echo 'Tutorial using PHP and PDO';

//variables to establish connection
$server = getenv('IP');
$pass = "";
$user = getenv('C9_USER');
$db = "c9";

//Try catch block for SQL statements
    //String to create & connect to database
    $connect = new PDO("mysql:host=$server;dbname=$db", $user, $pass);
    echo "
Created & Connected";
    //String to create table
    $line = "create table hello_world ( id int(2) auto_increment primary key,
                                        string varchar(50) not null,
                                        value varchar(10));";
    //$line = "drop table if exists hello_world";
    echo "
Table created";
    //Prepare for multiple entries
    $line2 = $connect->prepare("insert into hello_world(string, value)
                values (:string, :value)");
    $line2->bindParam(':string', $str);
    $line2->bindParam(':value', $val);          
    $str = 'Obioku Obotette';
    $val = 'Name';
    $str = 'Another User';
    $val = 'Blank';
    echo "
Lines inserted into table";
    //retrieve data
    $line3 = $connect->prepare("select * from hello_world");
    //$print = $line3->setFetchMode(PDO::FETCH_ASSOC);
    foreach($line3->fetchAll() as $show){
        echo "
//Catch exception
}catch(PDOException $e)
    echo "
Error Occurred.".$e->getMessage();

No comments:

Post a Comment

Thank you very much for viewing this entry and I hope you are able to return soon to continue to enjoy more of the site.
Please share your thoughts in the comment section.
Be blessed and enjoy life!

Note: Only a member of this blog may post a comment.