PHP MySQL Connectez-vous à une base de données


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ètreDescription
servernameFacultatif. Spécifie le serveur pour se connecter à. La valeur par défaut est "localhost: 3306"
nom d'utilisateurFacultatif. 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 passeFacultatif. 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
?>


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);
?>

15 commentaires:

  1. When I initially commented I appear to have clicked the -Notify me when new comments
    are 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

    ReplyDelete
  2. I am truly glad to glance at this weblog posts which
    includes plenty of useful information, thanks for providing such information.



    Feel free to visit my web page: hardwood flooring

    ReplyDelete
  3. 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.

    Also visit my page: hardwood flooring

    ReplyDelete
  4. 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
    more often. Did you hire out a designer to create your theme?

    Great work!

    Visit my web-site ... hardwood floors prices

    ReplyDelete
  5. Good post. I definitely love this website. Keep it up!

    My page :: hardwood flooring

    ReplyDelete
  6. I have read so many articles or reviews concerning the blogger
    lovers but this paragraph is really a good post, keep it up.


    Also visit my site - hardwood flooring

    ReplyDelete
  7. If you wish for to get a great deal from this piece of writing then
    you have to apply such strategies to your won blog.

    Visit my web-site - affordable hardwood flooring

    ReplyDelete
  8. Fine way of explaining, and nice post to get data concerning my presentation focus, which i am going to
    present in university.

    Check out my page ... toe nail fungus treatments
    My site - toenail fungus treatment

    ReplyDelete
  9. My programmer is trying to persuade me to move to .
    net 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

    ReplyDelete
  10. 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
    fastidious job.

    my web page ... hardwood floors
    my webpage :: wood floors

    ReplyDelete
  11. Undeniably believe that that you stated. Your favorite reason
    appeared 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

    ReplyDelete
  12. Its like you learn my thoughts! You appear to grasp so much approximately
    this, 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

    ReplyDelete
  13. Terrific work! This is the type of info that are supposed to be shared across the internet.
    Shame 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

    ReplyDelete
  14. Nice replies in return of this matter with real arguments
    and explaining everything regarding that.

    Also visit my homepage; Cheap Jerseys

    ReplyDelete
  15. 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.
    I'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 []

    ReplyDelete

HELLO VISITORS THANKS FOR YOUR VISIT AND COMMENT