Could someone translate this to mysql commands?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akis
    New Member
    • Feb 2011
    • 2

    Could someone translate this to mysql commands?

    Hello all
    I have a php code that connects with odbc in mdb database and I want to change that and connect to an mysql database
    the original code is :
    Code:
    <?php 
    
    # connect to a DSN "mydb"
    $connect = odbc_connect("mydb", "", "");
    
    # queries 
    $sql="SELECT * FROM Transactions"; 
    
    #perform the querries
    $rs=odbc_exec($connect, $sql) or die(" ".odbc_errormsg()); ; 
    
    
    if (!$rs)
    { 
    exit("Error in SQL");
    } 
    
    while (odbc_fetch_row($rs)){
    $mid=odbc_result($rs,"MerchantID");
    $mr=odbc_result($rs,"MerchantRef");
    $am=odbc_result($rs,"Amount");
    $cr=odbc_result($rs,"Currency");
    
    echo "$mid";
    echo "$mr";
    echo "$am";
    echo "$cr";
    
    # close the connection
    odbc_close($connect);
    ?>
    Can someone change the command to connect with mysql?
    I tried but I cant handel it. It gives error when I try to change the odbc_exec and odbc_fetch_row.
    Connection string is ccdatabase,loca lhost,root,nopa ssword

    Thanks in advance.
  • akis
    New Member
    • Feb 2011
    • 2

    #2
    Code:
    <?php 
    	
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    
    $dbname = 'ccdb';
    mysql_select_db($dbname);
    $sql="SELECT * FROM transactions"; 
    
    $result = mysql_query($sql) or die(mysql_error());
    
    if (!$conn)
    { 
    exit("Error in SQL");
    } 
    
    while ($row =mysql_fetch_array($result)){
    $mid=$row['MerchantID']." ";
    echo $mid;
    $mr=$row['MerchantRef'];
    echo $mr;
    $am=$row['Amount'];
    echo $am;
    $cr=$row['Currency'];
    echo $cr;
    
    
    $am=$am/100;
    echo "$am";
    
    $crncy=$_POST["Currency"];
    $crncy= "0" . $crncy;
    echo "$crncy";
    
    # close the connection
    mysql_close($conn);
    ?>
    I change to this code . It connects but I can get the variables works.
    I get :
    Notice: Undefined index: Currency in C:\wamp\www\pro ject\order\vali dation.php on line 56
    line 56 : $crncy=$_POST["Currency"];
    Last edited by akis; Feb 17 '11, 08:20 PM. Reason: explanation

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      It means you are not returning data from a field named 'Currency'

      Comment

      • NetDynamic
        New Member
        • Feb 2011
        • 27

        #4
        "Notice" errors are just that.. Notices..

        Comment

        Working...