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 8 of 8
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts

    My conversion to mysqli

    Hi, well i started converting my smaller script and so far not so bad, just wanted to share some observations on the conversion.

    First the initial part is not that bad,

    mostly its just adding 'i' to all the mysql statements.

    "I have corrected my text here regarding the name change to num rows, it was incorrect." Fou-Lu has conrrected me below, thanls Fou-Lu

    Also it appears now you need to add your connection to every query unless you want to create and call a function to do this.
    Used to be mysql would just default to the open connection but i guess now you must tell it which one specifically.

    Event the db_connect has to have 2 parameters now,
    ($connection, $dbname)

    And even the mysqli_real_escape_string has to have 2 parameters now ($connection, $string) That means i am having to add an include to my functions to include the db connection file in order to use the escape inside the function.

    I do hope thats about it, cause i hate to have to go thru these files again lol..
    Last edited by durangod; 01-26-2013 at 04:51 PM. Reason: corrected my misinformation text

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    mysqli_num_rows and mysqli_stmt_num_rows are two different things. One comes from instance of MySqliResult and the other from MySqliStatement (whilst the statement is stored with store_result). The latter is used with prepared statements and the former with raw query.
    MySQLi is object oriented to which they added a procedural interface. You'll need to always provide an instance as the first argument for almost every command. Its also no longer an autoglobal, so you'll need to pass it into function parameters to gain scope.
    This is the way the mysql library should have been written in the first place.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    Thanks, so what your saying is that if i use mysqli_stmt_num_rows then i will need to:
    prepare the query
    execute the query
    store the query
    close the query

    for each query, because it is object oriented.

    But i could use mysqli_num_rows to simply replace my mysql_num_rows in most cases without issue. Of course i mean this under the simplist usage example.

    What thru me off is this.

    http://php.net/manual/en/function.mysql-num-rows.php

    It does refer you to use the stmt example so i honestly had no idea where was a i version of the basic num rows.
    Last edited by durangod; 01-26-2013 at 04:58 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yes and no. For each separate query yes, you need to do all of those steps, but that is no different than how you are doing it now. Storing is required since statements won't know what is happening until you have finished what you need to do.
    mysqli_num_rows can be used to replace raw queries which are objects of type MySQLiResult. Procedurally is a pain only because the functions are not overloaded to take either parameter and deal with them in a single function call. One or the other will throw an error when used in conjunction with the incorrect object datatype.
    Using it object oriented doesn't suffer from this same problem since both MySQLi_Result and MySQLi_Stmt (looks like those are the actual class names) both contain the properties num_rows. So whichever you use, you can call $var->num_rows on it.
    Statements should be used when you accept any non-hard coded input. Raw can be done when its all hard coded. Statements can be used for both, so its up to you if you want to mix and match the two or just use statements. Statements don't require (and shouldn't be performed on as it will corrupt the data) any escaping, so they make a lot more sense to use than raw querying.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

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

    durangod (01-26-2013)

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    WOW im almost done with the smaller script, it was easier for me to just split up the query and grab the object on most every query, that way at least everything is uniform.

    but wow word to the wize, put connection in almost everything cause even mysqli_error requires the connection.

    I know one thing, my large script with about 1200 files is going to be madening to convert lol i dont drink now but i might before its done lol...

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,316
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    One of the major reasons I put off switching was purely because of the amount of extra hassle involved. More to the point I wrote a very nice and very handy mysql connection thingy which I was rather pleased with which will now be effectively useless.

    Bah humbug.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    @tangoforce is "thingy" a technical term lol..
    I have heard of watchumacallit, gizmo. That must be a smaller thingybob lol

    Yeah i hear ya, i did a couple of really nice classes for all my query's all in one place, very few of them in the file and now ill have to go thru that again. I agree bah humbug!

    Its not that difficult its just mind numbing work.

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,316
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by durangod View Post
    @tangoforce is "thingy" a technical term lol..
    I have heard of watchumacallit, gizmo. That must be a smaller thingybob lol
    It most certainly is

    It's a descendant of the Thingamebob which descends from the thingybob you mention which is in the Doo-da class

    The Doo-da was an updated version of the now depracated Didgerydoo which was originally created by some ozzie bloke by the surname of Harris for an instrument he couldn't find a name for
    Last edited by tangoforce; 01-27-2013 at 01:57 AM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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