PHP MySQL Créer base de données et tableaux


PHP MySQL Créer base de données et tableaux

Une base de données contient un ou plusieurs tableaux.

Créer une base de données

L'instruction CREATE DATABASE est utilisé pour créer une base de données de MySQL.

Syntaxe

CREATE DATABASE database_name

Pour en savoir plus sur SQL, s'il vous plaît visitez notre tutoriel SQL .
Pour obtenir de PHP pour exécuter l'instruction ci-dessus, nous devons utiliser la fonction mysql_query () la fonction. Cette fonction est utilisée pour envoyer une requête ou une commande à une connexion MySQL.

Exemple

L'exemple suivant crée une base de données appelée "my_db":
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>


Créer un tableau

L'instruction CREATE TABLE est utilisée pour créer une table dans MySQL.

Syntaxe

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....

)
Pour en savoir plus sur SQL, s'il vous plaît visitez notre tutoriel SQL .
Il faut ajouter l'instruction CREATE TABLE à l'mysql_query () pour exécuter la commande.

Exemple

L'exemple suivant crée une table nommée "personnes", avec trois colonnes. Les noms de colonnes seront "FirstName", "Nom" et "Age":
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>
Important: Une base de données doit être sélectionnée avant une table peut être créée. La base de données est sélectionné avec le mysql_select_db () la fonction.
Remarque: Lorsque vous créez un champ de base de données de type varchar, vous devez spécifier la longueur maximale du champ, par exemple, varchar (15).
Le type de données indique quel type de données de la colonne peut contenir. Pour une référence complète de tous les types de données disponibles dans MySQL, consultez notre complète des types de données de référence .

Des clés primaires et des champs d'incrémentation automatique

Chaque tableau doit avoir un champ de clé primaire.
Une clé primaire est utilisé pour identifier de manière unique les lignes d'une table. Chaque valeur de clé primaire doit être unique dans la table. En outre, le champ de clé primaire ne peut pas être nulle parce que le moteur de base de données requiert une valeur pour localiser l'enregistrement.
L'exemple suivant définit le champ PersonneID que le champ de clé primaire. Le champ de clé primaire est souvent un numéro d'identification, et est souvent utilisé avec le paramètre AUTO_INCREMENT. AUTO_INCREMENT augmente automatiquement la valeur du champ de 1 à chaque fois qu'un nouvel enregistrement est ajouté. Pour s'assurer que le champ de clé primaire ne peut pas être nulle, il faut ajouter le paramètre NOT NULL dans le champ.

Exemple

$sql = "CREATE TABLE Persons
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)";

mysql_query($sql,$con);

37 commentaires:

  1. Hello, sir i would like to ask that what is the scope of Php mysql training, what all topics should be covered and it is kinda bothering me … and has anyone studies from this course http://www.wiziq.com/course/5871-php-mysql-with-basic-javascript-integrated-course of core and advance java online ?? or tell me any other guidance...
    would really appreciate help… and Also i would like to thank for all the information you are providing on java concepts.

    ReplyDelete
  2. Incredible! This blog looks just like my old one! It's on a totally different topic but it has pretty much the same page layout and design. Superb choice of colors!
    installing hardwood floors

    Visit my blog post; hardwood floor

    ReplyDelete
  3. Hi there! Do you use Twitter? I'd like to follow you if that would be ok. I'm undoubtedly enjoying your blog and look forward to new
    posts.

    my page: zetaclear nail fungus relief

    ReplyDelete
  4. There's definately a lot to find out about this subject. I like all of the points you have made.

    Also visit my web page - zetaclear nail fungus relief

    ReplyDelete
  5. Thanks for sharing your thoughts on eczema treatment. Regards

    Also visit my blog; toe nail fungus treatments

    ReplyDelete
  6. These are genuinely fantastic ideas in regarding blogging.
    You have touched some fastidious things here. Any way
    keep up wrinting.

    Also visit my blog post - nail fungus treatment

    ReplyDelete
  7. I seldom comment, but i did some searching and wound up here "PHP MySQL Cr�er base de donn�es et tableaux".
    And I actually do have 2 questions for you if you usually do not mind.
    Could it be just me or does it give the impression like some of
    the responses appear as if they are written by brain dead people?
    :-P And, if you are writing on other sites, I'd like to keep up with anything fresh you have to post. Would you list of the complete urls of your public pages like your linkedin profile, Facebook page or twitter feed?

    my blog housekeeping service

    ReplyDelete
  8. Hi! Quick question that's completely off topic. Do you know how to make your site mobile friendly? My web site looks weird when browsing from my iphone 4. I'm trying to find a theme or plugin that might be able to resolve this issue.
    If you have any recommendations, please share.
    Appreciate it!

    My page ... phoenix house cleaning
    My website: cleaning services phoenix

    ReplyDelete
  9. Incredible points. Outstanding arguments. Keep up the good
    spirit.

    Here is my web-site hair growth cycle

    ReplyDelete
  10. I think the admin of this site is really working
    hard in support of his web page, as here every stuff is quality
    based data.

    my site http://wetfouru.com/index.php/blogs/39132/146556/herbal-cosmetics-related-article

    ReplyDelete
  11. I like the helpful info you provide in your articles. I'll bookmark your blog and check again here frequently. I am quite sure I will learn many new stuff right here! Good luck for the next!

    My homepage - toe fungus treatment

    ReplyDelete
  12. Very good information. Lucky me I found your blog by chance (stumbleupon).

    I have bookmarked it for later!

    My web page 360fmtv.com

    ReplyDelete
  13. First of all I want to say terrific blog! I had a quick question that I'd like to ask if you don't mind.
    I was interested to find out how you center yourself and clear your mind before writing.
    I've had a hard time clearing my thoughts in getting my thoughts out. I truly do enjoy writing however it just seems like the first 10 to 15 minutes are wasted simply just trying to figure out how to begin. Any ideas or tips? Appreciate it!

    Stop by my blog :: internet maarketing

    ReplyDelete
  14. I like what you guys are usually up too. This kind of clever work and
    exposure! Keep up the amazing works guys I've you guys to my blogroll.
    linux dedicated servers

    Have a look at my page; discount commodities broker

    ReplyDelete
  15. What's up, I desire to subscribe for this website to obtain latest updates, therefore where can i do it please help.

    My blog; black and white food photography

    ReplyDelete
  16. Greetings from Los angeles! I'm bored to tears at work so I decided to check out your website on my iphone during lunch break. I really like the info you provide here and can't wait to take a
    look when I get home. I'm amazed at how quick your blog loaded on my mobile .. I'm not even using
    WIFI, just 3G .. Anyhow, great site!

    my blog - Call of Duty: Modern Warfare 2 Hacks pro trainer version 2

    ReplyDelete
  17. Thanks a lot for sharing this with all of us you actually recognize what
    you are talking approximately! Bookmarked. Kindly
    additionally seek advice from my site =).
    We could have a hyperlink alternate arrangement between us

    Feel free to visit my web blog Get Twitter User Data Back

    ReplyDelete
  18. I have геad ѕo many content about
    the blogger lovеrs but this post is rеally a good paгagraph,
    keep it up.

    Also visit my page; disque dur SSD

    ReplyDelete
  19. I really like it when people get together and share views.
    Great site, keep it up!

    My weblog - LOL videos

    ReplyDelete
  20. Very rapidly this web page wіll be famous among all
    bloggіng and site-building people, due to it's pleasant content

    Check out my weblog; devis fenetres

    ReplyDelete
  21. I have been browsing on-line greater than 3 hours
    these days, but I never discovered any attention-grabbing article like yours.
    It's lovely worth sufficient for me. In my view, if all website owners and bloggers made good content material as you did, the internet can be a lot more helpful than ever before.

    Review my webpage: twitter hack

    ReplyDelete
  22. Hey! I could have sworn I've been to this site before but after browsing through some of the post I realized it's new to me.
    Anyhow, I'm definitely glad I found it and I'll be bookmarking and checking back often!


    my blog post ... psn

    ReplyDelete
  23. Howdy! I know this is kind of off-topic however I had to ask.
    Does running a well-established website like yours require a massive amount work?
    I am brand new to blogging but I do write in my journal every day.
    I'd like to start a blog so I will be able to share my personal experience and views online. Please let me know if you have any ideas or tips for new aspiring bloggers. Appreciate it!

    Here is my homepage: earn money from Internet

    ReplyDelete
  24. Hi fantastic blog! Does running a blog similar to this require a
    great deal of work? I've virtually no expertise in coding however I had been hoping to start my own blog in the near future. Anyways, should you have any ideas or tips for new blog owners please share. I understand this is off subject however I just wanted to ask. Thanks!

    Also visit my web page; free online cheat

    ReplyDelete
  25. I have read so many content concerning the blogger lovers but this article is really a good article, keep
    it up.

    Feel free to visit my site ... university of delaware

    ReplyDelete
  26. What's up, after reading this amazing article i am too happy to share my know-how here with friends.

    Also visit my weblog; the best cheats

    ReplyDelete
  27. I do accept as true with all the ideas you have presented on
    your post. They are very convincing and will definitely work.
    Still, the posts are too brief for beginners.
    Could you please extend them a bit from subsequent time?
    Thank you for the post.

    my page: free minecraft giftcode

    ReplyDelete
  28. Very rapidly this web site will be famous amid all blog viewers, due to it's good content

    My blog post - dragonvale Hack no jailbreak download

    ReplyDelete
  29. It's the best time to make some plans for the future and it's time to be happy.
    I've read this post and if I could I wish to suggest you few interesting things or suggestions. Maybe you could write next articles referring to this article. I wish to read even more things about it!

    Here is my blog post Rolland Garros

    ReplyDelete
  30. you're truly a excellent webmaster. The site loading pace is incredible. It seems that you are doing any unique trick. Also, The contents are masterpiece. you've done
    a fantastic job on this matter!

    Also visit my web-site; voyance par téléphone

    ReplyDelete
  31. It's amazing in favor of me to have a web site, which is good in support of my experience. thanks admin

    My page; meuble salle de bain pas cher

    ReplyDelete
  32. If you would like to grow your familiarity just keep visiting
    this site and be updated with the most up-to-date
    information posted here.

    Here is my web site :: play minecraft full version free online

    ReplyDelete
  33. I have been browsing online more than three hours today,
    yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the internet will be much more useful than ever before.


    my web blog: Adf.ly free clicker tool download

    ReplyDelete
  34. Hurrah! After all I got a website from where I be able to in fact take useful data
    regarding my study and knowledge.

    my weblog - psn code generator

    ReplyDelete
  35. Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
    I think that you can do with some % to drive the
    message house a bit, but other than that, this is excellent blog.
    A great read. I will certainly be back.

    Also visit my homepage :: sharecash bypass ()

    ReplyDelete
  36. Greetings from Colorado! I'm bored to tears at work so I decided to browse your website on my iphone during lunch break. I enjoy the info you present here and can't
    wait to take a look when I get home. I'm surprised at how fast your blog loaded on my phone .. I'm not even using WIFI,
    just 3G .. Anyways, very good site!

    Feel free to visit my site - video sharing software

    ReplyDelete
  37. It's hard to come by experienced people for this subject, however, you sound like you know what you're talking about!
    Thanks

    My web page :: hack a twitter

    ReplyDelete

HELLO VISITORS THANKS FOR YOUR VISIT AND COMMENT