All posts by mesala

Apache2 dir.conf

Dir konfiguraatiolla voidaan asettaa automaattinen tiedoston avaaminen kansiotasolla. Prioriteetti on suurin listan ensimmäisellä tiedostolla ja viimeisellä tiedostolla on heikoin prioriteetti.

Tyypillinen dir.conf, huomioi että DirectoryIndex tiedot tulee olla yhdellä rivillä, ei rivitettynä usealle riville.

DirectoryIndex index.html index.pl index.php index.xhtml index.htm Index.html Index.htm Index.php INDEX.HTML INDEX.HTM main.html main.htm koti.htm koti.html koti.php Koti.php main.php home.html home.htm home.php 1.html 1.htm 1.php start.html start.htm start.php Start.html Start.htm Start.php

Using insert ID

It’s very common to insert data in multiple tables: a book followed by its author, a customer followed by their purchase, and so on. When doing this with an autoincrement column, you will need to retain the insert ID returned for storing in the related table.
For example, let’s assume that these devices can be “sold” to a person. New device is stored in the device table, we also want to create a key to tie it to the device to a owner. The code to do this is similar to that in, except that the returned insert ID is stored in the variable $insertID and is then used as part of the subsequent query

Now the cat is connected to its “owner” through the devices unique ID, which was created automatically by AUTO_INCREMENT.

Example for insert

AUTO_INCREMENT

When using AUTO_INCREMENT, you cannot know what value has been given to a column before a row is inserted. Instead, if you need to know it, you must ask MySQL afterward using the mysql_insert_id function. This need is common: for instance, when you process a purchase, you might insert a new customer into a Customers table and then refer to the newly created CustId when inserting a purchase into the Purchases table.

Using AUTO_INCREMENT is recommended instead of selecting the
highest ID in the id column and incrementing it by one, because
concurrent queries could change the values in that column after the
highest value has been fetched and before the calculated value is
stored.

Adding data to the devices table and reporting the insert ID

Adding Data information

Adding data to the devices table

You may wish to add a couple more items of data by modifying $query as follows and calling up the program in your browser again:

$query = “INSERT INTO devices VALUES(NULL, ‘Minidisc’, ‘Sony’, 2)”;
$query = “INSERT INTO devices VALUES(NULL, ‘Dat’, ‘Sony’, 3)”;

By the way, notice the NULL value passed as the first parameter? This is because the id column is of type AUTO_INCREMENT, and MySQL will decide what value to assign according to the next available number in sequence. So, we simply pass a NULL value, which will be ignored. Of course, the most efficient way to populate MySQL with data is to create an array and insert the data with a single query.