PHP to ASP

Last post 12-31-2007 7:00 AM by iceguy. 9 replies.

Sort Posts:

  • PHP to ASP

    12-24-2007, 12:23 PM
    • Loading...
    • iceguy
    • Joined on 12-17-2007, 11:43 PM
    • Posts 8
    Can any one help in translating this piece of code from PHP tp ASP or ASP.NET?

    if ($action == "delete") {
       // delete a record
       $upsql = "SELECT * FROM users WHERE id='$id'";

       $upresult = mysql_query($upsql);

       $upmyrow = mysql_fetch_array($upresult);
       $oldref = $upmyrow["ref"];
    if ($oldref) {
       $usql = "UPDATE users SET refs=refs-1 WHERE id='$oldref'";
       $uresult = mysql_query($usql);
    }
        $sql = "DELETE FROM users WHERE id='$id'";
        $result = mysql_query($sql);
        echo "$id deleted!";
    }
    Thanks In Advance
    iceguy
  • Re: PHP to ASP

    12-24-2007, 12:33 PM

    With ASP.NET, what language are you using and which database?  If you are using Sql Server, that looks to me like it would pretty much all go into a stored procedure.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: PHP to ASP

    12-24-2007, 12:41 PM
    • Loading...
    • iceguy
    • Joined on 12-17-2007, 11:43 PM
    • Posts 8
    I am using VB and want this to connect to a MYSQL database.
  • Re: PHP to ASP

    12-26-2007, 12:39 AM
    Answer

    Hi iceguy,

    You can refer to the VB.NET sample here:

    http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommand(VS.71).aspx

    You need to specify the connection string to your database.

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: PHP to ASP

    12-29-2007, 12:36 PM
    • Loading...
    • iceguy
    • Joined on 12-17-2007, 11:43 PM
    • Posts 8
    Unfortunately, this does not help me. I need to know what is happening with the array and how i can get a recordset result in to a an array.I need to know how accomplish mysql_fetch_array function of php using asp
  • Re: PHP to ASP

    12-29-2007, 12:55 PM

    You don't need to fiddle around with arrays in ASP.NET.  You can use a DataReader, which provides forward-only, read-only access to the data, or you can fill a datatable, which is disconnected from the database.  However, since you only appear to be using one value retrieved from the database, you should only select that and use ExecuteScalar.

    One other thing - instead of coding a condition to detect whether the $action == delete, you would put this code in a button click event handler for a Delete button. 

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: PHP to ASP

    12-29-2007, 1:05 PM
    • Loading...
    • iceguy
    • Joined on 12-17-2007, 11:43 PM
    • Posts 8
    can you please convert the code block to asp for me?
  • Re: PHP to ASP

    12-29-2007, 1:11 PM

    Can you tell me what it does?  My php is extremely rusty.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: PHP to ASP

    12-31-2007, 3:36 AM
    Answer

    Hi,

    Yes.

            Dim action As String = ""
            Dim id As String = ""

            Dim myConnString As String = "" 'TODO: Please change it to your connection string
            Dim myConnection As New OleDbConnection(myConnString)

            myConnection.Open()


            If action = "delete" Then


                Dim upsql As String = "SELECT * FROM users WHERE id=" & id


                Dim myCommand As New OleDbCommand(upsql, myConnection)
               
                Dim myReader As OleDbDataReader = myCommand.ExecuteReader()

                myReader.Read()
          
                If myReader.HasRows Then

                    Dim oldref As String
                    oldref = myReader.GetInt32(0).ToString()

                    Dim usql As String = "UPDATE users SET refs=refs-1 WHERE id=" & oldref

                    myCommand.CommandText = usql
                    myCommand.ExecuteNonQuery()


                End If

                myReader.Close()

                Dim sql As String = "DELETE FROM users WHERE id=" & id

                myCommand.CommandText = sql
                myCommand.ExecuteNonQuery()


                Response.Write("$id deleted!")

            End If

            myConnection.Close()

     

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: PHP to ASP

    12-31-2007, 7:00 AM
    • Loading...
    • iceguy
    • Joined on 12-17-2007, 11:43 PM
    • Posts 8
    Hi Zhao Ji Ma, Thanks a lot. this really solved my problem. I am new to ASP.NET. and trying to learn as much as i can from the forum. your answer helped me a lot in understanding the PHP code.
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter