Local Installation PHP SQL and Connect
Local Installation PHP SQL and Connect
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
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
<?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