Database Connectivity in PHP??

Discussion in 'PHP' started by sumitt_2004, May 7, 2008.

  1. #1
    Hi,

    I am a learner of PHP by myself. I just started to learn it! I am facing a problem in connectivity with database. Please check the given detail and tell me how to fetch data from database and where I am wrong.

    Database Name : dynamicsite
    Table Names : 1) meta 2) pg_layout

    conn.php
    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'sumit';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    $dbname = 'dynamicsite';
    mysql_select_db($dbname, $conn);
    ?>

    phone.php
    <?php include "conn.php";
    $pagename = $_GET["ph"];
    $pagename = trim(str_replace("-", " ", $pagename));
    $query = "select title, description, keyword from meta where pg_name=$pagename;";
    $result = mysql_query($query);
    ?>
    <html>
    <head>
    <title><?php echo $pagename . $result['title']; ?></title>
    <meta name="description" content='<?php echo $result["description"]; ?>' />
    <meta name="keywords" content='<?php echo $result["keyword"]; ?>' />
    </head>

    Is this information enough??
     
    sumitt_2004, May 7, 2008 IP
  2. sumitt_2004

    sumitt_2004 Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    IS there anybody? who can help me!
     
    sumitt_2004, May 7, 2008 IP
  3. Sabbir

    Sabbir Banned

    Messages:
    210
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Hi, you just run this script in your server. then if you get any error, write the error here.
    Hope we will be able to help you.

    thnaks
     
    Sabbir, May 7, 2008 IP
  4. weblover78

    weblover78 Banned

    Messages:
    226
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you write error here we will help you otherwise we cannot
     
    weblover78, May 7, 2008 IP
  5. sumitt_2004

    sumitt_2004 Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There is not any error. But, I can't fetch data.
     
    sumitt_2004, May 7, 2008 IP
  6. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #6
    password should be empty, if your using root
    (mysql by default has no password, and if your developing your site by your localhost then password should be empty)

    fetching your records by executing
    mysql_fetch_array($youvariable);

    just replied to your pm, hope this helps.
     
    bartolay13, May 7, 2008 IP
  7. ggggqqqqihc

    ggggqqqqihc Peon

    Messages:
    92
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ggggqqqqihc, May 7, 2008 IP
  8. swordbeta

    swordbeta Banned

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Your doing it wrong...
    You need to work with the function mysql_fetch_array, do the querry first and then the fetch array function.
    Example:
    $query = "SELECT * FROM meta pg_name=$pagename"; 
    	 
    $do_query = mysql_query($query) or die(mysql_error());
    
    $result = mysql_fetch_array($do_query) or die(mysql_error());
    echo $result['title']." - ".$result['description']."-".$result['keyword'];
    PHP:
     
    swordbeta, May 7, 2008 IP
  9. sumitt_2004

    sumitt_2004 Peon

    Messages:
    154
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for all suggestions. bartolay13 gave me solution of my problem. Thanks bartolay13!
     
    sumitt_2004, May 8, 2008 IP