0% found this document useful (0 votes)
23 views3 pages

Local Installation PHP SQL and Connect

step to have a sql and php portable ap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Local Installation PHP SQL and Connect

step to have a sql and php portable ap
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Local installation php sql and connect

download php from php.net

for window
https://windows.php.net/download/
and download ZIP file and extrack all at new folder Server C:/Server/
with a name you choice
C:Server/php

download sqlite from sqlite.org

for window
https://www.sqlite.org/download.html

and download ZIP file and extrack all at new folder Server C:/Server/
with a name you choice
C:Server/sql

open a sql folder and run with double click the sqlite.exe

type
sqlite>.open myDB.db
sqlite>CREATE TABLE IF NOT EXISTS my_table(
[id] VARCHAR(20) UNIQUE NOT NULL,
[name] VARCHAR(20),
[last_name] VARCHAR(20)
);
sqlite>INSERT INTO "my_table"(id,name,last_name)
VALUES('00045','joe','Doe');

sqlite>.exit

Now look in folder sql you see a new file myDB.db

at php folder create folder<name-like junior> and create file


<name-like hello.php> write the code inside

<?php
$host="../../sql/myDB.db";
$user="";
$password="";
$dbname="myDB";

try {
$conn = new PDO("sqlite:". $host , $user, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$result = $conn->query("SELECT name FROM my_table");

foreach($result as $row)
{
print $row['name'] . "\n";
}

?>
from command prompt go to php/junior folder and type
php hello.php
and you see export
Connected successfullyjoe

You might also like