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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts

    MYSQLI Advise - Help ETC..

    What are the benifits to MYSQLI than MYQSL?

    What are the new items you can do that you could not do with MYSQL


    How should the queries look in MYSQLI compared to MYSQL..

    How soon should we change to this?


    Thanks.. Slayer.

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    There are numerious improvements over Mysql including security, function application as well as result improvement.

    The problem with listing all the features here in your post is that Mysql is going away regardless if anyone likes it or not. So unless your host is planning to stay on PHP5.4 or below you WILL have to do this eventually regardless of any benefits.

    I personally dont know when they plan to release it, PHP 5.5 is just now in Alpha so it will be awhile im guessing. I personally am planning for inside 2 years. Which will pass quicker than you think.

    Luckily i am with a host that i do some work for (barter) and they have agreed to hold off updating to 5.5 even after release to make sure their scripts and customers scripts are updated first. Most dont have that option and you may find yourself in a corner, so i would suggest starting now. Just my opinion.

    also read this thread, good info..
    Why is mysql_query getting deprecated?
    Last edited by durangod; 02-06-2013 at 06:10 PM.

  • Users who have thanked durangod for this post:

    SlayerACC (02-06-2013)

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,462
    Thanks
    0
    Thanked 633 Times in 623 Posts
    The simplest change from mysql_ to mysqli_ involves adding the 'i' into the function name and swapping the two parameters around the other way (or adding the database parameter if you were leaving it out.

    You can then apply all the enhanced features when you are ready. These include

    - Being able to use mysqli_ calls in an object oriented way.
    - Being able to keep the SQL and data separate by using PREPARE and BIND instead of QUERY

    You should get rid of all the mysql_ references as quickly as possible so that you can start applying the additional security features and so better protect your database from attack. It doesn't take long to do a basic conversion - an hour should suffice to convert a few hundred web pages. Actually applying the new features will take longer but you can do that a call at a time once you have converted across.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    SlayerACC (02-06-2013)

  • #4
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    Thank you for your quick replies..

    I understand the change will happen regardless... as you know change is not always our friend...

    In this case I ask if you can give examples of a connect to the database, a select and a count of such.

    I currently have about 5 or 6 sites that I have to start with the change over to the new MYSQLI however.. I want to try to make this a seem less as possible.

    for example: mysql
    PHP Code:
    $results mysql_query("SELECT * FROM TABLE")
    or die(
    mysql_error());

    while(
    $row mysql_fetch_array$results )) {

    echo 
    $row['name'];


    Example 2: MYSQLI
    PHP Code:
    $result $mysqli->query("SELECT * FROM TABLE");
    while (
    $row $result->fetch_assoc()) {


    echo 
    $row['name'];


    What would this be in MYSQLI?
    PHP Code:
    or die(mysql_error()); 
    Would it be this
    PHP Code:
    or die(mysqli_error()); 

    Man Change Sucks!!!

    How do we support the other items such as count, search pages etc?

    Thanks, Slayer

  • #5
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Procedural:

    PHP Code:
    mysqli_error($link
    $link being new mysqli(...);

  • Users who have thanked TFlan for this post:

    SlayerACC (02-06-2013)

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    Yep TFlan is correct remember SlayerACC that in many cases now you need to add the db link where you did not require it before. Some of it depends on how you perform the task, if you use statments or if you stick with object oriented or stay with procedural style.

    The way i understand it, in general if you use statments then you need to open the statement, bind (prepare)the statement, execute the statement, then close the statement each time you use it.

    have a look at this

    http://www.php.net/manual/en/mysqli....statements.php

    there are certainly benefits to having more controls over the process but i chose to stick with object oriented simply because it was quicker and because in my small scripts some of the NON benefits really did not hurt me or the process. So it was just the best call for me.

    What i mean by object oriented for me anyway (i guess its actually proceedural) but i like to think of it is object because i have an object result) is this, lets take your example of Mysql and convert it the way i did to MySQLi procedural style



    Your example:

    PHP Code:

    $results 
    mysql_query("SELECT * FROM TABLE"
    or die(
    mysql_error()); 

    while(
    $row mysql_fetch_array$results )) { 

    echo 
    $row['name']; 


    Here is the conversion the way i did it.

    PHP Code:

    $query 
    "SELECT * FROM TABLE"
    $results mysqli_query($link,$query)or die(mysqli_error($link)); 

    while(
    $row mysqli_fetch_array$results )) { 

    echo 
    $row['name']; 


    Hope that helps
    Last edited by durangod; 02-06-2013 at 08:30 PM. Reason: forgot the i in error lmao and had to clarify what i consider object oriented for me

  • #7
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Please do not take what Durangod has said about his code being object oriented to mind.

    It is not.

    He is using the procedural style, just as you are, NOT object oriented style of the mysqli library.

  • #8
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    Quote Originally Posted by TFlan View Post
    Please do not take what Durangod has said about his code being object oriented to mind.

    It is not.

    He is using the procedural style, just as you are, NOT object oriented style of the mysqli library.
    I also stated i considered it object oriented for me in my mind and i explained what i meant by that. I guess i could have shown him without that explaination and just left all that out and just put the code, but in my case my object thinking comes from the old coding practices way before the internet and i still think that way even if it is not the Technical term for it now.

    Sorry for the confusion..

  • #9
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    I understand where you are coming from, but for the sake of explanation, that could confuse the OP. Especially in this case with the new library the OP is learning

  • #10
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    Thanks for the explaination.

    You guys are alot of help... thanks.

    Looking to put some of this to work today... starting a new site and needed to get this figured..

    Slayer.


  •  

    Posting Permissions

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