www.webdeveloper.com
Results 1 to 7 of 7

Thread: SQL -> MySQL Functions (I need Help)

  1. #1
    Join Date
    Jan 2004
    Posts
    312

    SQL -> MySQL Functions (I need Help)

    I am new to databasing, I started using sql with our server, I want to do work outside my office, and the server I have setup uses mysql. To my understanding sql and mysql are similar or the same, am I wrong? This are basic funtions that I use to connect and do simple funtions to my database with sql. Can someone help me rewrite the few code snippets I provided to mysql. I tried doing this myself and I just can't get it to work. If someone can help, thanks so much, this means alot. I don't need complex codes, just the basics I provided but in mysql code. Thanks in advance.

    DB

    PHP Code:
    <!-- INSERT INTO DATABASE -->

    <?php

    $ser
    ="111.111.0.0";
    $db="database";
    $user="username";
    $pass="password";

    $conn odbc_connect($db$user$pass); 

    $conn odbc_connect($db$user$pass); 
    $query "INSERT INTO tablename (Entry1, Entry2, Entry3) VALUES ('$Entry1', '$Entry2', '$Entry3')";

    odbc_do($conn$query);

    ?>
    <html>
    <!-- HTML PAGE CODE HERE -->
    </html>
    <?php
    odbc_close
    ($conn); 
    ?>




    <!-- UPDATE DATABASE -->

    <?php

    $ser
    ="111.111.0.0";
    $db="database";
    $user="username";
    $pass="password";

    $conn odbc_connect($db$user$pass); 
    $query "UPDATE tablename SET Entry1 = '$Entry1', Entry2 = '$Entry2', Entry3 = '$Entry3' WHERE Info ='$Info'";

    odbc_do($conn$query);
    ?>
    <html>
    <!-- HTML PAGE CODE HERE -->
    </html>
    <?php
    odbc_close
    ($conn); 
    ?>




    <!-- DELETE FROM DATABASE -->

    <?php

    $ser
    ="111.111.0.0";
    $db="database";
    $user="username";
    $pass="password";

    $conn odbc_connect($db$user$pass); 
    $query "DELETE FROM tablename WHERE Entry1 = '$Entry1'"

    odbc_do($conn$query);
    ?>
    <html>
    <!-- HTML PAGE CODE HERE -->
    </html>
    <?php
    odbc_close
    ($conn); 
    ?>




    <!-- VIEW INFO FROM DATABASE -->

    <?php

    $ser
    ="111.111.0.0";
    $db="database";
    $user="username";
    $pass="password";

    $id $_GET['id'];
    $conn odbc_connect($db$user$pass); 
    $query "SELECT * FROM tablename WHERE Entry1 = '" $id "'"

    odbc_do($conn$query);
    ?>
    <html>
    <?php   
    while($myrow=odbc_fetch_array($result)) {   
        echo(

        Entry1: <input name="Entry1" value="'
    .$myrow['Entry1'].'"><br> 
        Entry2: <input name="Entry2" value="'
    .$myrow['Entry2'].'"><br> 
        Entry3: <input name="Entry3" value="'
    .$myrow['Entry3'].'"><br>
        '
    );  
    }   
    }  
    ?> 
    </html>
    <?php
    odbc_close
    ($conn); 
    ?>

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    try this:
    PHP Code:
    <?php
    $link 
    mysql_pconnect('111.111.0.0''username''password');
    mysql_select_db('database'$link);

    $result mysql_query("INSERT INTO `tablename` (`Entry1`, `Entry2`, `Entry3`) VALUES ('$Entry1', '$Entry2', '$Entry3')"$link);
    ?>
    PHP Code:
    <?php
    $link 
    mysql_pconnect('111.111.0.0''username''password');
    mysql_select_db('database'$link);

    $result mysql_query("UPDATE `tablename` SET `Entry1` = '$Entry1', `Entry2` = '$Entry2', `Entry3` = '$Entry3' WHERE `Info` = '$Info'"$link);
    ?>
    PHP Code:
    <?php
    $link 
    mysql_pconnect('111.111.0.0''username''password');
    mysql_select_db('database'$link);

    $result mysql_query("DELETE FROM `tablename` WHERE `Entry1` = '$Entry1'"$link);
    ?>
    PHP Code:
    <?php
    $link 
    mysql_pconnect('111.111.0.0''username''password');
    mysql_select_db('database'$link);

    $result mysql_query("SELECT * FROM `tablename` WHERE `Entry1` = '{$_GET['id']}'"$link);

    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {
        echo 
    "Entry1: <input name=\"Entry1\" id=\"Entry1\" value=\"{$row['Entry1']}\"><br>
      Entry2: <input name=\"Entry2\" id=\"Entry2\" value=\"
    {$row['Entry2']}\"><br>
      Entry3: <input name=\"Entry3\" id=\"Entry3\" value=\"
    {$row['Entry3']}\"><br>
    "
    ;
    }
    ?>

  3. #3
    Join Date
    Jan 2004
    Posts
    312
    Do I need to close the connection like in sql?

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    the function mysql_pconnect() creates a persistant database connection, you can not use mysql_close() on it, you can only use mysql_close() with mysql_connect()

  5. #5
    Join Date
    Jan 2004
    Posts
    312
    I have my "INSERT" like this: I get no errors, yet not data is put into the database!?

    PHP Code:
    <?php 
    $conn 
    mysql_connect('database''username''password'); 
    mysql_select_db('database'$conn); 

    $result mysql_query("INSERT INTO `cart_owners` (`First_Name`, `Last_Name`) VALUES ('$First_Name', '$Last_Name')"$conn); 
    ?> 

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Form</title>
    </head>

    <body>
    <form action="insert.php" method="post" enctype="multipart/form-data">
    First Name: <input name="First_Name"><br>
    Last Name: <input name="Last_Name"><br>
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>
    <?php
    mysql_close
    ($conn); 
    ?>
    Last edited by d.brandusa; 07-30-2004 at 05:29 PM.

  6. #6
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107
    To my understanding sql and mysql are similar or the same
    Just a bit of information, SQL stands for structured query language. SQL is pretty much the same for all databases on all platforms. Some DB's enhance their functionalty and have proprietary statement calls but it all remains the same.
    Bittersweet web development.

  7. #7
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    PHP Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Form</title>
    </head>
    <body>
    <?php
    if($_POST)
    {
        
    $conn mysql_connect('database''username''password');
        
    mysql_select_db('database'$conn);
        
    $result mysql_query("INSERT INTO `cart_owners` (`First_Name`, `Last_Name`) VALUES ('{$_POST['First_Name']}', '{$_POST['Last_Name']}')"$conn);

        if(
    $result !== false && mysql_affected_rows($conn) != 0)
        {
            echo 
    "information sucessfully added to database";
        }
        else
        {
            echo 
    mysql_error($conn);
        }
        
    mysql_close($conn);
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data">
      First Name:
      <input name="First_Name"><br>
      Last Name:
      <input name="Last_Name"><br>
      <input type="submit" value="Submit">
    </form>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles