SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Connection to MYSQL database

    Hi,

    I hope everyone had a good Easter !!

    I am new to the forum and have little experience to using MYSQL, PHP and Apache.

    I am running Red Hat Linux 8.0
    PHP 4.4.2 ?
    MYSQL v11.18 Distrib. 3.23.52.

    So far I have managed to get PHP to work and am using the example in the PHPand MYSQL dummies book (the Pet Catalog) to understand how everything works, so I can create my own database. Also I used the example program to write the SQL to the server and also I managed to write SQL to MSQL sever directly.

    The error that I keep getting is "Cannot connect to the database.

    When I do a status on the MYSQL server it comes up with the following message :-

    mysql Ver 11.18 Distrib 3.23.52 for pc-linux -gnu (i686)
    connection id 1
    current database NONE
    current user root@localhost
    current pager stdout
    using outfile ' '
    Server version 3.23.52
    Protocol version 10
    connection Localhost via UNIX socket
    client characterset latin1
    server characterset latin1
    Unix socket /var/lib/mysql/mysql.sock

    Threads 1 Questions 2 Slow Queries 0 Opens 6 Flush Tables 1 Open Tables 0 Queries per second avg 0.009

    Any help to my problem would be much appreciated !!

    Regards,

    midge.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2002
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you able to create and connect to a new db? If not, the must be something in the setup that's not quite right. Sorry I can't be more helpful.

    Nick
    All4YourPC for all your PC needs. Custom software.
    Websites. Web marketing. Training.
    http://members.aol.com/nickjc67

  3. #3
    SitePoint Member vaporware's Avatar
    Join Date
    May 2004
    Location
    North Carolina
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hope this helps

    The code is in the zip file too. Just in case it got scrambled or something.
    PHP Code:
    <?php
     
    echo "
     <HTML>
     <HEAD></HEAD>
     <BODY>"
    ;
    // Define your connection variables below
    $dbhost "localhost"// Usually localhost or 127.0.0.1
    $dbname "Database_Name";
    $dbuser "username";
    $dbpass "password";

    // Define your table name below and we will create a table too
    $tablename "Your_Table";

    // These will be the columns inside your table
    $col1 "username";
    $col2 "email";

    // Let's insert a username and password in the above
    $col1insert "Your_name";
    $col2insert "Your_email";



                  
    // We are gonna try to connect here
    $connect mysql_connect("$dbhost""$dbuser""$dbpass")
      or die (
    "Could not connect to MySQL" mysql_error());


      
    /* Assuming your running locally and not on the web
             We will try to create the database now
      If you are using this code on the internet comment the code out
     below to create a database and create the database from the control panel then execute this code.*/
    $create mysql_create_db("$dbname")or die("Create Error: ".mysql_error());
             if(
    $create)
             echo 
    "<b>$dbname created!! </b><br>";


             
    // Now let us select the database we just created
    mysql_select_db ("$dbname")
      or die (
    "Could not select database" mysql_error);


             
    // Ok Let's make that table I promised you now
     
    $create_table mysql_query("CREATE TABLE $tablename
     (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), 
    $col1 VARCHAR(16),
     
    $col2 VARCHAR(16))")or die("Create table Error: ".mysql_error());

                       
    // Display result below
                      
    if($create_table == true)
                      echo 
    "<b>Table $tablename created</b><br>";


               
    // Adding fields to the columns now
       
    $result mysql_query("INSERT INTO $tablename ($col1$col2)
        VALUES ('
    $col1insert','$col2insert')")or die("Insert Error: ".mysql_error());

                 
    // Display result
                 
    if($result == true)
                 echo 
    "<b>$col1insert inserted into $col1<br>
             
    $col2insert inserted into $col2</b><HR width=\"50%\" align=\"left\">";

                  
    // Diplaying your database table below. Pretty ain't it ;)
            
    $result mysql_query"SELECT * FROM $tablename)
    or die(
    "SELECT Error: ".mysql_error());
    $num_rows mysql_num_rows($result);
    print 
    "<b><br><br><br>Here is your table inside of $database $dbname.<br> Good Job!!</b>\n";
    print 
    "<br><br><table width=200 border=1>\n";
    while (
    $get_info mysql_fetch_row($result)){
    print 
    "<tr>\n";
    foreach (
    $get_info as $field)
    print 
    "\t<td><font face=arial size=3/><b>$field</b></font></td>\n";
    print 
    "</tr>\n";
    }
    print 
    "</table>\n";





            
    // Closing connection
             
    mysql_close($connect);

          echo 
    "
          </BODY>
        </HTML>"
    ;
    ?>
    Attached Files Attached Files


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
  •