We launched a new IT training category! Check out the 140+ courses now.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Setting permissions for a database

From: SQLite 3 with PHP Essential Training

Video: Setting permissions for a database

One of the defining characteristics of the SQLite database management system is that it keeps each database in a single file. If your database is going to run in a UNIX-based environment, which includes many, if not most, web servers, then you'll need to understand how to set file permissions so that your application can access the database. Here we are working on a Mac, running Mac OS X, which happens to be UNIX-based, and so we have this issue of file permissions. This is the directory where the data is being kept, and if I right-click on this and bring up Get Info - if you also on a Mac, follow along if not, just watch - you'll notice down here at the bottom we have the permissions for this folder.

Setting permissions for a database

One of the defining characteristics of the SQLite database management system is that it keeps each database in a single file. If your database is going to run in a UNIX-based environment, which includes many, if not most, web servers, then you'll need to understand how to set file permissions so that your application can access the database. Here we are working on a Mac, running Mac OS X, which happens to be UNIX-based, and so we have this issue of file permissions. This is the directory where the data is being kept, and if I right-click on this and bring up Get Info - if you also on a Mac, follow along if not, just watch - you'll notice down here at the bottom we have the permissions for this folder.

It says Read & Write permissions for Me, and it says Read & Write permissions for everyone. That's what allows the web server, which runs as a different user, to be able to create files in that directory. If I change this to Read only, which is the default, when I created that directory this was the way that it came up, and then I come in here and tried to run my createdatabase database script, you'll notice that it fails. It says "bwSQLite could not create database," "unable to open database file." That means that the permissions on the directory were not allowing the web server to create a file in that directory.

So, if I come back over here, and I change this to Read & Write for everyone and then I run this program again, you'll see that it successfully created the database, and there it is in the folder. You'll also notice that when I Get Info on that files that it's owned by nobody. The web server is running as a user called nobody, and this is typical of shared web hosts. So, in order for that nobody user to be able to create files in this directory, the permissions on the directory itself which is owned by Me, must allow Read & Write permissions for others.

On the Mac, that's called everyone; on some operating systems it's called others, or world. Now, if you're not running on a Mac, or even if you are running on a Mac and your script is going to be running on a server some place that happens to be a UNIX-based server, like many of them are, then you'll need to know how to set these permissions on the remote server. So let's take a look at how we do that. Here I have a program called Transmit which is the file transfer program, the FTP program that I'm using. It doesn't matter what FTP program you're using or if you are using something else on a different operating system; the techniques are going to be the same. The actual keystrokes and button presses might be a little bit different, but here is what you are going to look for.

This is the folder where I am keeping the data on that server. When I right-click on it, and usually if I am in a program that I'm not familiar with, and I am looking for how to do this, that's going to be the first thing I'm going to try, so I am going to right-click on it, and I am going to select Get Info here. You'll look for something in this pop-up menu, or in one of the menus at the top of the program that says something about setting permissions or getting info or something like that on the file, where you might expect to find this dialog box. Here is the dialog box that we are looking for. This is the information on that file. It's got its file Size.

It's got the Modified date. It says who the owner of the file is. That's the User account that created it, and then it's got the permissions themselves. The permissions are often displayed in several different forms. Typically, if you're a UNIX person like I am, you'll recognize this; this is the octal bits of the file. Anybody who has worked with UNIX for a long time knows with that means. If you don't know what that means, don't worry about it. It's automatically updated. You are going to use these check boxes here, and you'll notice that there are permissions for User.

In this case, that's the same as Owner, billw - that's me. There are permissions for Group, and you are not going to worry about that and all. In this case, that's also me because this is owned by me without being set to a group. And then there are permissions for World, which is the same as everyone on the Mac or other on some other operating systems, and here it says world. So, that's the one that you are concerned with, because the web server is running as a different user than the owner of the file. So, here it's checked Read, Write and Execute. In the case of the directory, or a folder, the Execute bit serves a different purpose than it does with regular files.

The Execute bit is the bit that says that it's a directory, so you need to leave that checked. But if I were to uncheck this one here, which is Write permissions for World - you'll notice that these other displays get updated; you need to worry about that - and I press Apply, and now I go in, and I run the createdatabase script on the server which I have loaded up over here, you see, I get that same error; "could not create the database, unable to open database file." Now, if I come back here and bring this up again, that's still up there actually, and I checked that right and I press Apply, now I go back over to the web browser and run the script again, you see, it successfully created the file.

So, we'll close this, and we need to reload the directory because it's on a remote server so it doesn't do that automatically, and there is the file that we created from that script. So, understanding file permissions is going to save you a lot of trouble and headaches if your database application is going to run on a UNIX-based system. Keep in mind that the host application, that's the web server in this case, contains the SQLite driver, and it must have Read, Write and Create permissions in the folder where you create the database file.

Show transcript

This video is part of

Image for SQLite 3 with PHP Essential Training
SQLite 3 with PHP Essential Training

98 video lessons · 8038 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 44s
    1. Welcome
      1m 26s
    2. What is SQLite and what are the prerequisites?
      1m 49s
    3. Using the exercise files
      2m 29s
  2. 41m 36s
    1. Getting the most out of the quick start
      4m 8s
    2. Creating and using a database
      10m 33s
    3. Inserting data into a table
      8m 17s
    4. Getting data from a table
      4m 38s
    5. Updating data in a table
      4m 31s
    6. Deleting data from a table
      4m 12s
    7. Creating a database library
      5m 17s
  3. 39m 19s
    1. Installing XAMPP on a Mac
      5m 59s
    2. Installing XAMPP on a PC
      4m 45s
    3. Setting up SID and exercise files on a Mac
      9m 10s
    4. Setting up SID and exercise files on a PC
      8m 12s
    5. Using the command-line tools
      11m 13s
  4. 30m 44s
    1. Understanding databases and tables in SQLite
      2m 34s
    2. Creating a database
      5m 45s
    3. Setting permissions for a database
      5m 24s
    4. Defining a table in SQL
      2m 21s
    5. Creating a table in PHP
      3m 34s
    6. Creating indexes
      4m 38s
    7. Indexing ID fields
      6m 28s
  5. 36m 35s
    1. Taking care with data types in SQLite
      9m 33s
    2. Storing numbers with INTEGER
      5m 17s
    3. Storing numbers with REAL
      2m 15s
    4. Storing text
      3m 15s
    5. Storing large data with BLOB
      9m 31s
    6. Storing booleans
      2m 24s
    7. Storing dates and times
      4m 20s
  6. 22m 47s
    1. Storing data with INSERT
      4m 1s
    2. Updating data with UPDATE
      3m 12s
    3. Reading data with SELECT
      6m 14s
    4. Reading data from multiple tables with JOIN
      5m 29s
    5. Deleting data with DELETE
      3m 51s
  7. 24m 45s
    1. Understanding expressions in SQLite
      2m 31s
    2. Comparing values with comparison operators
      4m 36s
    3. Matching patterns with LIKE
      4m 28s
    4. Building simple math with arithmetic operators
      3m 13s
    5. Matching values in a list with IN
      2m 22s
    6. Choosing from multiple conditions with the CASE expression
      4m 45s
    7. Forcing a data type with CAST
      2m 50s
  8. 24m 38s
    1. Finding the LENGTH of a string
      1m 52s
    2. Changing case with UPPER and LOWER
      2m 15s
    3. Reading parts of a string with SUBSTR
      2m 34s
    4. Changing parts of a string with REPLACE
      1m 17s
    5. Trimming blank spaces with TRIM
      1m 59s
    6. Reading absolute values with ABS
      1m 6s
    7. Rounding values with ROUND
      1m 42s
    8. Finding the data type of an expression with TYPEOF
      1m 14s
    9. Finding the last inserted record with LAST_INSERT_ROWID
      1m 7s
    10. Getting the version of your SQLite library
      1m 16s
    11. Creating user-defined functions
      4m 51s
    12. Building aggregate user-defined functions
      3m 25s
  9. 18m 58s
    1. Understanding aggregate functions
      2m 15s
    2. Counting rows with COUNT
      3m 30s
    3. Building with the SUM and TOTAL functions
      2m 9s
    4. Finding minimum and maximum values with MIN and MAX
      4m 33s
    5. Finding averages with AVG
      1m 50s
    6. Grouping results with GROUP BY
      2m 23s
    7. Selecting for aggregation with HAVING
      2m 18s
  10. 13m 54s
    1. Understanding SQLite support for dates and times
      4m 31s
    2. Getting readable, sortable dates and times
      3m 36s
    3. Getting high-resolution dates and times with JULIANDAY
      2m 49s
    4. Formatting dates and times with STRFTIME
      2m 58s
  11. 18m 7s
    1. Understanding collation
      1m 0s
    2. Sorting results with ORDER BY
      1m 30s
    3. Removing duplicate results with DISTINCT
      2m 5s
    4. Understanding indexes
      3m 18s
    5. Working with primary key indexes
      4m 12s
    6. Understanding how to use the INTEGER PRIMARY KEY function
      6m 2s
  12. 7m 52s
    1. Understanding transactions
      1m 10s
    2. Using transactions in SQLite
      6m 42s
  13. 16m 6s
    1. Understanding subselects
      1m 29s
    2. Creating a simple subselect
      3m 18s
    3. Searching within a result set
      2m 35s
    4. Searching within a joined result
      3m 59s
    5. Creating a view
      2m 17s
    6. Searching within a joined view
      2m 28s
  14. 15m 56s
    1. Understanding triggers in SQLite
      52s
    2. Automatically updating a table with a trigger
      5m 18s
    3. Logging transactions with triggers
      2m 41s
    4. Improving performance with triggers
      2m 3s
    5. Preventing unintended updates with triggers
      2m 50s
    6. Adding automatic time stamps
      2m 12s
  15. 16m 25s
    1. Choosing an interface
      1m 21s
    2. Using the SQLite3 interface
      2m 41s
    3. Using the PDO interface
      3m 0s
    4. Creating a library
      9m 23s
  16. 16m 33s
    1. Defining CRUD
      4m 5s
    2. Using PHP to open and use an SQLite database
      3m 36s
    3. Using PHP to insert into an SQLite database
      4m 18s
    4. Using PHP to read from an SQLite database
      2m 20s
    5. Using PHP to update an SQLite database
      1m 2s
    6. Using PHP to delete from an SQLite database
      1m 12s
  17. 11m 32s
    1. An overview of the testimonials application
      4m 48s
    2. Managing the database in PHP
      4m 5s
    3. Displaying the testimonials using PHP
      2m 39s
  18. 32s
    1. Goodbye
      32s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed SQLite 3 with PHP Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.