MySQL - Insert

E-mail Εκτύπωση PDF
Αξιολόγηση Χρήστη: / 0
ΧείριστοΆριστο 

Εισαγωγή δεδομένων:
Όταν εισάγουμε δεδομένα (inserting data) σε κάποιο table πρέπει να λαμβάνουμε υπόψην το είδος των δεδομένων το οποίο μπορεί να αποθηκευτεί σε κάθε column. Δηλαδή άν προσπαθήσουμε να εισάγουμε μια πρόταση σε κάποιο column το οποίο αποθηκεύει ακεραίους 3 χαρακτήρων τότε θα πάρουμε ένα μήνυμα λάθους.
Παράδειγμα:
// Make a MySQL Connection
mysql_connect("localhost", "admin", "password") or die(mysql_error());
// Select a database
mysql_select_db("database") or die(mysql_error());

// Insert a row of information into the table "example"
mysql_query("INSERT INTO example
(name, age , weight) VALUES('Tom', '23', '70' ) ")
or die(mysql_error());

// Insert another row of information into the table "example"
mysql_query("INSERT INTO example
(name, age, weight) VALUES('John', '21', '60' ) ")
or die(mysql_error());

// Insert another row of information into the table "example"
mysql_query("INSERT INTO example
(name, age, weight) VALUES('Bill', '15', '40' ) ")
or die(mysql_error());

// Insert another row of information into the table "example"
mysql_query("INSERT INTO example
(name, age) VALUES('Bob', '50' ) ")
or die(mysql_error());
echo "Data Inserted!";

?>

Συντακτικό:
mysql_query("INSERT INTO example
Εισάγωγή δεδομένων στο table με όνομα example

(name, age , weight) VALUES('Tom', '23', '70' ) ")
Πρώτα όρίζουμε τα columns στα οποία θέλουμε να εισάγουμε δεδομένα και μετά αντίστοιχα τις τιμές.Οι τιμές βρίσκονται μέσα σε εισαγωγικά και κάθε τιμή χωρίζεται απο την επόμενη με τον χαρακτήρα ",".
Σε αυτό το παράδειγμα εισάγουμε στο column name την τιμή Tom, στο coloumn age την τιμή 23 και στο coloumn weight την τιμή 70.
(name, age) VALUES('Bob', '50' ) ")
Στο τελευταίο παράδειγμα αφήνουμε κενό το column weight, δηλαδή δεν το αναφέρουμε στην εντολή ενώ εισάγουμε τιμές στα columns name και age τις αντίστοιχές τιμές Bob και 50. Σε αυτό το παράδειγμα το column weigth παίρνει αυτόματα την τιμή 0 ή NULL ανάλογα με το είδος του.



Μοιραστείτε αυτό το άρθρο
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! Yahoo! Dig Me Joomla Free PHP

Σχόλια
Προσθήκη νέου Αναζήτηση RSS
Γράψτε σχόλιο
Όνομα:
Email:
 
Τίτλος:
 
Please input the anti-spam code that you can read in the image.
Τελευταία Ενημέρωση ( Σάββατο, 28 Μάρτιος 2009 22:34 )  

Seach By Google

Translate this website :

Επιλογές


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

Programming


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

Fedora


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

CentOS


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

Linux


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

Ubuntu


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99

Debian


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/flakgr/public_html/libraries/joomla/cache/handler/callback.php on line 99


Τελευταία Σχόλια