Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts

    Anyone has an example of mysql query using OOP?

    Hello,

    anyone has an example of mysql query using OOP?

    example..

    PHP Code:
    $query="select * from users where user_id='$userid'";
    $result=mysql_query($query);
    $row=mysql_fetch_array($result);

    echo 
    $row[name]; 
    how to convert that into oop approach?

    thanks...

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    26
    Thanks
    0
    Thanked 4 Times in 4 Posts
    PHP Code:
    $mysqli = new mysqli("localhost""my_user""my_password""world");

    if (
    mysqli_connect_errno()) 
    {
       
    printf("Connect failed: %s\n"mysqli_connect_error());
       exit();
    }

    $query "SELECT * FROM users WHERE user_id='$userid'";

    if (
    $result $mysqli->query($query)) 
    {
       while (
    $row $result->fetch_assoc()) 
       {
           echo 
    $row['name'] ."<br />";
       }
       
    $result->close();
    }

    $mysqli->close(); 


  •  

    Posting Permissions

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