Results 1 to 3 of 3

Thread: How to connect PHP to mySQL Database

  1. #1
    Join Date
    Jun 2009

    How to connect PHP to mySQL Database

    PHP syntax is very similar to the syntax of C or Perl. People familiar with programming will be able to very quickly begin to write programs in PHP. In this language there is no strict data typing and there is no need for action on allocation / freeing memory. MySQL - compact multi-threaded database server. MySQL is characterized by a high speed, stability and ease of use. MySQL is the ideal solution for small and medium-sized applications. MySQL supports a query language in the ANSI SQL 92, and in addition has a set of extensions to this standard are not found in any other database. MySQL is really a very fast server.

    Retrieving Records from a MySQL database using PHP is one of the most common tasks is presented every web developer.
    • First Create a Database. To save, read, modify, or delete data, you must first establish a connection to MySQL as described above via a file-like connexion.php.
    • To get the data from MySQL need a connection (a form of link or communication), which will allow us to extract data from it. This PHP has a number of unique features to interact with mysql . Then to connect use the function mysql_connect mysql_select_db which then allows us to define which database server you want to connect.
    • Now the other part is obtaining records from the database. Once you had made a connection to extract the data, you will need to send SQL queries using mysql_query function. By this you can also get the total number of records returned by your query.
    • Behind these two terms are hidden concepts. The dataset is a direct response to a query in MySQL. The dataset contains 0, 1, 2 ... No records. Each record is a DataRow as the data line. In fact, when asked MySQL, it returns a block of responses (dataset) that we will peel with php (DataRow DataRow by).
    • To use PHP via this line, we use the command mysql_fetch_array ($ dataset): This command creates an associative array where each key corresponds to each column of the table, and each value for each value read from the dataset.
    • print_r will display the source code.
    • Remember that array keys are case-sensitive, if the column is called MySQL Manufacturer or producer, this is not the same. It only remains to show the information required in PHP (sample code in a html page named pieces.php).

    Connection to Server
    • To send queries to MySQL, you must first have access, that is to say, have been registered by the administrator of the mysql database.
    • It should then connect to the server using the mysql_connect (all functions php / mysql start with mysql_).
    • This function calls as arguments the name of the host machine where the MySQL server, the name of the authorized user and the password for that user.
    • This will attempt to connect to the MySQL database server which runs on the host INFRES under the username.
    • It is obvious that in practice, the password should never be placed in a plain php script: the arguments of this function will be entered in the first place by a form whose implementation will start by trying the log with the information provided by the user. Once the connection is established, you can use the manipulation of databases.

  2. #2
    Join Date
    Mar 2010

    Re: How to connect PHP to mySQL Databse

    The base function to connect database is mysql_connect (). This function accepts three input arguments: the host name, user name, password. The function returns a link that must store messages and nicknames in a variable for use later. To close the connection, use mysql_close (). This function takes as argument the variable connection to close. In the same way to connect database - mysql_select_db (). This function takes as argument the name of a database and a variable returned by mysql_connect () in our example $ connection. If this variable is not provided, then the function utlise the last established connection.

  3. #3
    Join Date
    May 2009

    Re: How to connect PHP to mySQL Databse

    I use a different method on my system to integrate both. The first thing we need is to get the DLLs to connect to a SQL Server, by default these DLLs in the package will not install automatically, so you're down, if you have not already, the packet with the complete installation. You must tell PHP to have a new library and that should be used. So edit the php.ini in Notepad, usually php.ini is in C: \ WINNT. Find the line that says extension_dir = and modify it to point to the directory where we copied the DLL. With This tells PHP where the extension DLL. Now find the line extension = php_mssql.dll and modify it by removing the principle. Save the file php.ini and you're done.

Similar Threads

  1. Connecting C# with MySQL database
    By Quattro in forum Software Development
    Replies: 5
    Last Post: 05-03-2010, 10:13 PM
  2. Need MySQL database directory
    By Osman84 in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 05:18 AM
  3. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  4. How to Connect to MySQL database on my website?
    By Zombi in forum Software Development
    Replies: 3
    Last Post: 24-09-2009, 01:23 PM
  5. How to Connect MySQL database from PHP
    By Booth in forum Software Development
    Replies: 3
    Last Post: 21-01-2009, 09:12 PM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Page generated in 1,713,377,416.64688 seconds with 17 queries