PHP MySQL Connectez-vous à une base de données
La base de données MySQL libre est très souvent utilisé avec PHP.
Créer une connexion à une base de données MySQL
Avant de pouvoir accéder aux données dans une base de données, vous devez créer une connexion à la base de données.
En PHP, cela se fait avec la fonction mysql_connect ().
Syntaxe
mysql_connect(servername,username,password);
Paramètre | Description |
---|---|
servername | Facultatif. Spécifie le serveur pour se connecter à. La valeur par défaut est "localhost: 3306" |
nom d'utilisateur | Facultatif. Indique le nom d'utilisateur de se connecter avec. La valeur par défaut est le nom de l'utilisateur qui possède le processus du serveur |
mot de passe | Facultatif. Spécifie le mot de passe pour vous connecter avec. Par défaut est "" |
Remarque: Il ya des paramètres plus disponibles, mais celles qui sont énumérées ci-dessus sont les plus importants. Visitez notre pleine PHP MySQL référence pour plus de détails.
Exemple
Dans l'exemple suivant, nous stockons la connexion dans une variable ($ con) pour une utilisation ultérieure dans le script. Le "die" une partie sera exécutée si la connexion échoue:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
Fermeture d'une connexion
La connexion sera fermée automatiquement lorsque le script se termine. Pour fermer la connexion avant, utilisez le mysql_close () la fonction:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
When I initially commented I appear to have clicked the -Notify me when new comments
ReplyDeleteare added- checkbox and now each time a comment is added
I get four emails with the same comment.
Is there an easy method you can remove me from that service?
Thanks!
hardwood floor refinishing
I am truly glad to glance at this weblog posts which
ReplyDeleteincludes plenty of useful information, thanks for providing such information.
Feel free to visit my web page: hardwood flooring
Excellent post. I was checking continuously this weblog and I'm inspired! Extremely helpful information specifically the last phase :) I deal with such info much. I used to be seeking this certain information for a long time. Thanks and best of luck.
ReplyDeleteAlso visit my page: hardwood flooring
I'm really enjoying the design and layout of your site. It's a very easy on the eyes which makes it much more enjoyable for me to come here and visit
ReplyDeletemore often. Did you hire out a designer to create your theme?
Great work!
Visit my web-site ... hardwood floors prices
Good post. I definitely love this website. Keep it up!
ReplyDeleteMy page :: hardwood flooring
I have read so many articles or reviews concerning the blogger
ReplyDeletelovers but this paragraph is really a good post, keep it up.
Also visit my site - hardwood flooring
If you wish for to get a great deal from this piece of writing then
ReplyDeleteyou have to apply such strategies to your won blog.
Visit my web-site - affordable hardwood flooring
Fine way of explaining, and nice post to get data concerning my presentation focus, which i am going to
ReplyDeletepresent in university.
Check out my page ... toe nail fungus treatments
My site - toenail fungus treatment
My programmer is trying to persuade me to move to .
ReplyDeletenet from PHP. I have always disliked the idea because of the costs.
But he's tryiong none the less. I've been using WordPress on numerous
websites for about a year and am worried about switching
to another platform. I have heard very good things about blogengine.
net. Is there a way I can import all my wordpress content
into it? Any help would be greatly appreciated!
My blog post toe nail fungus treatments
My site: zetaclear nail fungus relief
If some one wants expert view concerning blogging and site-building afterward i propose him/her to pay a visit this webpage, Keep up the
ReplyDeletefastidious job.
my web page ... hardwood floors
my webpage :: wood floors
Undeniably believe that that you stated. Your favorite reason
ReplyDeleteappeared to be at the net the simplest thing to be aware of.
I say to you, I certainly get annoyed at the same time as folks think about
concerns that they plainly do not recognize about.
You managed to hit the nail upon the highest as neatly as defined
out the whole thing without having side-effects , other people could take a signal.
Will likely be back to get more. Thank you
My web site :: zetaclear side effects
Its like you learn my thoughts! You appear to grasp so much approximately
ReplyDeletethis, like you wrote the guide in it or something.
I feel that you just can do with a few p.c. to drive the message home a bit,
but instead of that, that is great blog. A great read. I'll definitely be back.
My web site: phoenix cleaning service
Terrific work! This is the type of info that are supposed to be shared across the internet.
ReplyDeleteShame on the search engines for no longer positioning this post upper!
Come on over and seek advice from my site . Thank you =)
Here is my website ... housekeeping maid
Nice replies in return of this matter with real arguments
ReplyDeleteand explaining everything regarding that.
Also visit my homepage; Cheap Jerseys
Does your site have a contact page? I'm having a tough time locating it but, I'd like to send you an e-mail.
ReplyDeleteI've got some suggestions for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
Have a look at my web blog :: Louis Vuitton Handbags []