SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 180 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

And Finally we
display the result.
So what would this be like if we connected to a SQLite database?
$dsn = 'sqlite:abcd.db';
try
{
$pdo = new PDO($dsn);
$pdo->exec("CREATE TABLE users (id int, name VARCHAR)");
$pdo->exec("DELETE FROM users");
$pdo->exec("INSERT INTO users (name) VALUES('afif')");
$pdo->exec("INSERT INTO users (name) VALUES('tipu')");
$pdo->exec("INSERT INTO users (name) VALUES('robin')");
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$result = $pdo->query("select * from users");
foreach ($result as $row)
echo $row['name'];
?>
See there is no change in the code except the DSN.
Database in an OOP Way
[ 178 ]
You can also create a SQLite database in memory and perform the operation there.
Let's see the following code:
$dsn = 'sqlite::memory:';
try {
$pdo = new PDO($dsn);
$pdo->exec("CREATE TABLE users (id int, name VARCHAR)");
$pdo->exec("DELETE FROM users");
$pdo->exec("INSERT INTO users (name) VALUES('afif')");
$pdo->exec("INSERT INTO users (name) VALUES('tipu')");
$pdo->exec("INSERT INTO users (name) VALUES('robin')");
}
catch (PDOException $e)
{
echo 'Connection failed: ' .


Pages:
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6