SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    3
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to conenct to SQL using PHP.?

    Hi
    I want to know that how to connect a HTML code to the SQL using PHP. I have just created a form in HTML but I don't know how to connect it with the SQL of local server. So please help me.

    Thanks in advance.

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2011
    Location
    Kolding, Denmark
    Posts
    108
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    As you haven't mentioned which database exactly you are using, I will suggest using PDO, which covers most of the common databases.

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,067
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sid8 View Post
    Hi
    I want to know that how to connect a HTML code to the SQL using PHP. I have just created a form in HTML but I don't know how to connect it with the SQL of local server. So please help me.

    Thanks in advance.
    Just to be clear, are you referring to Microsoft SQL Server? Or are you using SQL as a generalized term for any Database?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    3
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am using Xampp Server for the PHP. So I want to connet to database of this server.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,067
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, you will need to know your username and password for your MySQL setup (it likely asked you this during installation)

    To Connect: http://www.php.net/manual/en/pdo.construct.php
    To Run a Query: http://www.php.net/manual/en/pdo.prepare.php
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,067
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    @sid8 ;

    If you'd like a tutorial approach, check out the latest postings from PHP Master: http://phpmaster.com/avoid-the-origi...l-extension-2/
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #7
    SitePoint Member imsas's Avatar
    Join Date
    Feb 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would connect as follows:

    mysql_connect(servername,username,password);

    Hope this helps.
    ___________________________________________________________________
    IMSAS Background Check - Background Check API
    PeopleSearchWorld.com - People Search
    fuzwire.com - Job Search

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,067
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imsas View Post
    You would connect as follows:

    mysql_connect(servername,username,password);

    Hope this helps.
    Um ... no. mysql_connect is being deprecated in the next release, so definitely not. You can use mysqli, but it is still preferred to move to PDO.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    3
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help frnds..I have done with it..

  10. #10
    Non-Member
    Join Date
    Feb 2013
    Location
    indore
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    You would connect as follows:
    In PHP, this is done with the mysqli_connect() function.
    This is the syntax for MySQL connect through php
    PHP Code:
    <?php
    // Create connection
    $con=mysqli_connect("example.com","peter","abc123","my_db");

    // Check connection
    if (mysqli_connect_errno($con))
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }
    ?>
    Last edited by cpradio; Feb 26, 2013 at 04:49. Reason: Added [php] tags


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •