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);
?>
$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,
....
)
(
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);
?>
$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);
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)";
mysql_query($sql,$con);
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...
ReplyDeletewould really appreciate help… and Also i would like to thank for all the information you are providing on java concepts.
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!
ReplyDeleteinstalling hardwood floors
Visit my blog post; hardwood floor
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
ReplyDeleteposts.
my page: zetaclear nail fungus relief
There's definately a lot to find out about this subject. I like all of the points you have made.
ReplyDeleteAlso visit my web page - zetaclear nail fungus relief
Thanks for sharing your thoughts on eczema treatment. Regards
ReplyDeleteAlso visit my blog; toe nail fungus treatments
These are genuinely fantastic ideas in regarding blogging.
ReplyDeleteYou have touched some fastidious things here. Any way
keep up wrinting.
Also visit my blog post - nail fungus treatment
I seldom comment, but i did some searching and wound up here "PHP MySQL Cr�er base de donn�es et tableaux".
ReplyDeleteAnd 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
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.
ReplyDeleteIf you have any recommendations, please share.
Appreciate it!
My page ... phoenix house cleaning
My website: cleaning services phoenix
Incredible points. Outstanding arguments. Keep up the good
ReplyDeletespirit.
Here is my web-site hair growth cycle
I think the admin of this site is really working
ReplyDeletehard 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
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!
ReplyDeleteMy homepage - toe fungus treatment
Very good information. Lucky me I found your blog by chance (stumbleupon).
ReplyDeleteI have bookmarked it for later!
My web page 360fmtv.com
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.
ReplyDeleteI 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
I like what you guys are usually up too. This kind of clever work and
ReplyDeleteexposure! 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
What's up, I desire to subscribe for this website to obtain latest updates, therefore where can i do it please help.
ReplyDeleteMy blog; black and white food photography
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
ReplyDeletelook 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
Thanks a lot for sharing this with all of us you actually recognize what
ReplyDeleteyou 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
I have геad ѕo many content about
ReplyDeletethe blogger lovеrs but this post is rеally a good paгagraph,
keep it up.
Also visit my page; disque dur SSD
I really like it when people get together and share views.
ReplyDeleteGreat site, keep it up!
My weblog - LOL videos
Very rapidly this web page wіll be famous among all
ReplyDeletebloggіng and site-building people, due to it's pleasant content
Check out my weblog; devis fenetres
I have been browsing on-line greater than 3 hours
ReplyDeletethese 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
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.
ReplyDeleteAnyhow, I'm definitely glad I found it and I'll be bookmarking and checking back often!
my blog post ... psn
Howdy! I know this is kind of off-topic however I had to ask.
ReplyDeleteDoes 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
Hi fantastic blog! Does running a blog similar to this require a
ReplyDeletegreat 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
I have read so many content concerning the blogger lovers but this article is really a good article, keep
ReplyDeleteit up.
Feel free to visit my site ... university of delaware
What's up, after reading this amazing article i am too happy to share my know-how here with friends.
ReplyDeleteAlso visit my weblog; the best cheats
I do accept as true with all the ideas you have presented on
ReplyDeleteyour 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
Very rapidly this web site will be famous amid all blog viewers, due to it's good content
ReplyDeleteMy blog post - dragonvale Hack no jailbreak download
It's the best time to make some plans for the future and it's time to be happy.
ReplyDeleteI'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
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
ReplyDeletea fantastic job on this matter!
Also visit my web-site; voyance par téléphone
It's amazing in favor of me to have a web site, which is good in support of my experience. thanks admin
ReplyDeleteMy page; meuble salle de bain pas cher
If you would like to grow your familiarity just keep visiting
ReplyDeletethis site and be updated with the most up-to-date
information posted here.
Here is my web site :: play minecraft full version free online
I have been browsing online more than three hours today,
ReplyDeleteyet 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
Hurrah! After all I got a website from where I be able to in fact take useful data
ReplyDeleteregarding my study and knowledge.
my weblog - psn code generator
Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
ReplyDeleteI 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 ()
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
ReplyDeletewait 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
It's hard to come by experienced people for this subject, however, you sound like you know what you're talking about!
ReplyDeleteThanks
My web page :: hack a twitter