Results 1 to 5 of 5

Thread: How to Run MySQL Queries with PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    How to Run MySQL Queries with PHP?

    I am very used-to with the SQL. I find very easy for SQL statements that are used to obtain data from database. Now the problem I am facing is that I don't know how to Run MySQL Queries with PHP? Since I am not having much knowledge about the PHP, can someone tell me the solution for running the MySQL in an easy way. any coding related to the topic will be greatly appreciable.!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: How to Run MySQL Queries with PHP?

    Since you know the SQL in better way, you should be knowing that when you run a select statement and receive a response, the data types of your response will be a string regardless of the data type of the column. Also you will have to make PHP interact with MySQL on your web site to deliver instant content. One thing I would like to tell you that Interacting with MySQL makes PHP a far more powerful tool. Usually most of the work done with MySQL involves pulling down data from a MySQL database. SQL queries can be used for data definition and manipulation and also used for data retrieval.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Jul 2006
    Posts
    286

    Re: How to Run MySQL Queries with PHP?

    The first thing for running MySQL Queries with PHP, is to create a database table. You can use the following code for creating the database table :
    Code:
    CREATE TABLE friends (name VARCHAR(30), fav_color VARCHAR(30), brands VARCHAR(30));
    INSERT INTO friends VALUES ( "Anna", "Red", "Adidas" ), ( "Tush", "Blue", "Reebok" ), ( "Kena", "Black", "Lewis" ), ( "Gaba", "Orange", "Koutons" )
    the above code will create a table for us to work with, that has friends' names, favorite colors, and brands. The first thing we need to do in our PHP file is connect to the database. We do that using this code :
    PHP Code:
    ?php
    // Connects to your Database
    mysql_connect("your.host.com""username""password") or die(mysql_error());
    mysql_select_db("Database_Name") or die(mysql_error());
    ?> 
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  4. #4
    Join Date
    Jul 2006
    Posts
    442

    Re: How to Run MySQL Queries with PHP?

    By using the mysql_connect() function, you can open a connection to your MySQL database from PHP. Just have a look on the coding which demonstrates the same.
    PHP Code:
    <?php
    mysql_connect
    ("www.address.com""username""password") or die(mysql_error()) ;
    mysql_select_db("Database_Name") or die(mysql_error()) ;
    ?>
    "When they give you ruled paper, write the other way..." J.R.J.

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to Run MySQL Queries with PHP?

    I have provided you with an example of PHP and MySQL code.
    PHP Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost""admin""admin1") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());

    $result mysql_query("SELECT * FROM demo")
    or die(
    mysql_error());  

    $row mysql_fetch_array$result );

    echo 
    "ID: ".$row['id'];
    echo 
    " Place: ".$row['place'];

    ?>

Similar Threads

  1. Optimizing queries in MySQL
    By Caden Fernandes in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 07:14 PM
  2. Replies: 3
    Last Post: 07-11-2009, 09:36 PM
  3. How to manage Parameterized Queries in MySQL
    By Zeverto in forum Software Development
    Replies: 3
    Last Post: 24-09-2009, 03:23 PM
  4. Show Number of MySQL Queries
    By Jagriti in forum Software Development
    Replies: 3
    Last Post: 28-07-2009, 03:17 PM
  5. Need to have multiple where queries in MySQL query
    By Anti_Trend in forum Software Development
    Replies: 1
    Last Post: 03-07-2009, 10:17 PM

Tags for this Thread

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
  •  
Page generated in 1,714,033,093.35961 seconds with 16 queries