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 3 of 3

Thread: using mysqli

  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts

    using mysqli

    Hi right now this script uses

    PHP Code:
    mysql_connect 
    to connect to db


    i would like to use

    PHP Code:
    mysqli_affected_rows 

    I hope this is an easy conversion im almost afraid to ask this lol.

    By chance is this just simply changing the class db to use

    PHP Code:
    mysqli_connect 
    instead of the old connect should i expect things to blow up in my face doing so..

    I dont suppose that the old mysql stuff works if you use mysqli right?
    Last edited by durangod; 11-28-2012 at 02:48 PM.

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    Nevermind, i was sitting here thinking having coffee and it hit me, that means i have to change all my mysql_query to mysqli_query, thats way too much ill do that one day but not now.

    ill just use mysql_affected_rows instead.


    what i was trying to do is do an error trap but the if not !result i could not get to flag on error so i guess for update you have to use affected rows right?

    just fyi this is what i did


    PHP Code:

    if($_POST['savecred'])
    {
     
    $issueid intval($_POST['issueid']);
     
    $numcred intval($_POST['numcred']);

     
    $query "UPDATE members SET mem_cred = mem_cred + $numcred WHERE mem_userid = '$issueid'";
     
    $qrest mysql_query($query,$link) or die(mysql_error());

    $didthisupdate mysql_affected_rows($link);

     if(
    $didthisupdate)
     {
     
    $confmsg "<span style='color:green;'>Credits have been issued</span>";
     }else{
            
    //used for troubleshootingonly
            //$confmsg  = 'Invalid query: ' . mysql_error() . "\n";

           
    $confmsg "<span style='color:red;'>Error - Credits not issued - verify userid (may not exist) or other error has occured</span>";      

          }
    //close else
    }//close if post savecred 
    Last edited by durangod; 11-28-2012 at 01:04 PM.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    mysql_affected_rows will result in any of the actual changes (potentially more; I believe that affected changes will also deal with the cascade count changes). Inserts, deletes and updates will all require affected rows to determine changes; selects, describes, etc, would make use of num_rows. MySQLi has a procedural equivalence to mysql, but they are not compatible together. Signatures are different between the libraries. MySQL usually allows the connection as an option (since for whatever reason they've globalized the resource), but it would be last argument. MySQLi requires the connection as its first argument or handled as an object.

    This is why with even procedural calls I recommend abstract functionality to stand between. You can't just swap out your storage drivers, you need to rewrite any code that uses the old storage drivers. If you had written the abstract functionality required, then you'd simply update a (hopefully) single inclusion to point at the file with the new functionality instead of the old.

  • Users who have thanked Fou-Lu for this post:

    durangod (11-28-2012)


  •  

    Posting Permissions

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