J
J
JackShcherbakov2018-02-01 19:01:10
PHP
JackShcherbakov, 2018-02-01 19:01:10

How to properly work with PHP PDO?

Hello! I'm reading a book on PHP and SQL (by David Sklar, page 201) which included this code:

$db = new PDO('sqlite:/tmp/restaurant.db'); //(1)
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)
$q = $db->exec("CREATE TABLE dishes (
                         dish_id INT,
                         dish_name VARCHAR(255) //(2)
                            //ну и так далее
)");

Here are my own questions:
(1) - what is the 'sqlite:/tmp/restaurant.db' path? There was no mention of such files in the book. Is this the path that specifies where to write the created database? Or what is it? How to do the same with sql (and not with sqlite)?
This is the path to the data base. But how to create it? How to make sure that this path is correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2018-02-01
@Maksclub

  1. sqlite - a simple database, roughly speaking, on files that works with SQL queries https://ru.wikipedia.org/wiki/SQLite, you do not need to connect to the database server with it, but you can use it almost immediately
  2. yes, this is a string with a maximum length of 255 characters, if there is more, it will give an error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question