SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nubie problems - Converting mysqli to mysql?

    Hi,

    I have a script that uses 'mysqli' to connect to a database, trouble is the shared server it is hosted on uses 'mysql' and so is producing unexpected results. Before pasting the php code into this thread, I was wondering whether there were any simply ways round this or scripts available that could sort this out for me or whether I have to go through the code changeing something and if so what?

    Or is it easier to look into moving to a dedicated server.

    cheers

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Why not just ask the host to use mysqli?
    You really should really find a host that is running at minimum PHP 5.3.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I have done, but they said that since it is a shared server they can't change setting like that, since they would have an effect on other sites hosted on the servers.

    The hosts are Namesco, so I assumed they would be using up to date hardware/software!

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    "Unexpected results". There should be no difference in results between mysqli and mysql. What query are you executing that's giving 'unexpected results'? (I'm guessing your query is ambiguous)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The unexpected results are that when used on an Apache server the script uploads and then displays a list of files stored in a database, where as on a zeus server no list is displayed. I have been all round the houses and the hosting company say my code is using the syntax 'mysqli' which is not enabled on the server. They suggested 'replacing all instances of 'mysqli' with 'mysql' and see if that rectifies the issue'. This then just produced a blank screen, and blank when viewing the source code of the page.

    Any ideas would be great.

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    From the sounds of it, you have a WPSE problem. Take a look at the Common PHP Errors thread, try what's in there.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If the code you have is using mysqli's object notation, or any other mysqli-specific prepared queries then you cannot just take off the i.

    You can only isolate the queries one at a time, and rewrite and test them.

    You should set up your local dev machine to run a mirror image of you live servers' setup, in order that you sort these issues out before committing code to live.

  8. #8
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, Addressed the WPSE problem. And now I can see the error messages I think I probably need.

    They all seem to point towards 'No such file or directory' problems but all the file paths are right as far as I can see.


    Warning: include_once(/content/Hosting/a/l/www.allianceleisure.co.uk/web/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/index.php on line 8

    Warning: include_once() [function.include]: Failed opening '/content/Hosting/a/l/www.allianceleisure.co.uk/web/includes/magicquotes.inc.php' for inclusion (include_path='.:/usr/local/fphp5/lib/php') in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/index.php on line 8

    Warning: mysql_set_charset() expects parameter 1 to be string, resource given in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 10

    Warning: include(output.html.php) [function.include]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13

    Warning: include(output.html.php) [function.include]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13

    Warning: include() [function.include]: Failed opening 'output.html.php' for inclusion (include_path='.:/usr/local/fphp5/lib/php') in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13


    Sorry, I did say I was a noobie.


  9. #9
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your includes contain both the ".html" and ".php" extensions. You only need the ".php"
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  10. #10
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oldfruitanting View Post
    Cool, Addressed the WPSE problem. And now I can see the error messages I think I probably need.

    They all seem to point towards 'No such file or directory' problems but all the file paths are right as far as I can see.


    Warning: include_once(/content/Hosting/a/l/www.allianceleisure.co.uk/web/includes/magicquotes.inc.php) [function.include-once]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/index.php on line 8

    Warning: include_once() [function.include]: Failed opening '/content/Hosting/a/l/www.allianceleisure.co.uk/web/includes/magicquotes.inc.php' for inclusion (include_path='.:/usr/local/fphp5/lib/php') in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/index.php on line 8

    Warning: mysql_set_charset() expects parameter 1 to be string, resource given in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 10

    Warning: include(output.html.php) [function.include]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13

    Warning: include(output.html.php) [function.include]: failed to open stream: No such file or directory in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13

    Warning: include() [function.include]: Failed opening 'output.html.php' for inclusion (include_path='.:/usr/local/fphp5/lib/php') in /content/Hosting/a/l/allianceleisure.co.uk/web/filestore/db.inc.php on line 13


    Sorry, I did say I was a noobie.

    No problem, we all start somewhere.

    In order:
    #1,2,4,5,and 6 all indicate that you're trying to include files that arnt where your script thinks they are.
    Take a look at the lines they mention, try and find out why they're failing.

    #3 indicates you might have gotten your parameters in the wrong order.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  11. #11
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Do you have a copy of this working on your local development machine, or is all the code on your live server?

  12. #12
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by USPaperchaser View Post
    Your includes contain both the ".html" and ".php" extensions. You only need the ".php"
    As a side note, this is most likely a naming convention used for seperating the files used for output (.html.php) from those used as function and setup (.inc.php), which allows for .htaccess based access rules.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  13. #13
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Do you have a copy of this working on your local development machine, or is all the code on your live server?
    It all works fine locally, and it works fine on a live apache server, the problem is, this particular site is, at the moment being hosted on a zeus server running mysqli not mysql.

  14. #14
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    No problem, we all start somewhere.

    In order:
    #1,2,4,5,and 6 all indicate that you're trying to include files that arnt where your script thinks they are.
    Take a look at the lines they mention, try and find out why they're failing.

    #3 indicates you might have gotten your parameters in the wrong order.
    Thanks Mr Lion for your help, I shall look into it, but I fear it may be better to look into moving the site to a dedicated server or one running Apache.

    Thanks again.

  15. #15
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    On your local site, what have you got listed against this line in your php.ini file:

    include_path=

    // live server contains this apparently :

    include_path='.:/usr/local/fphp5/lib/php'

  16. #16
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is this what you mean?!

    Quote Originally Posted by Cups View Post
    On your local site, what have you got listed against this line in your php.ini file:

    include_path=

    // live server contains this apparently :

    include_path='.:/usr/local/fphp5/lib/php'
    ; UNIX: "/path1:/path2"
    ;include_path = ".:/php/includes"
    ;
    ; Windows: "\path1;\path2"
    ;include_path = ".;c:\php\includes"

    cheers

  17. #17
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The lines starting with a ; are commented out - so they are not affecting your PHP installation.

    If you do not have a line which starts

    include_path =

    without a semi-colon then there is probably something inside your application it telling some bootstrap files where the include path lies.

    To be honest, there are a myriad reasons why an include file cannot be found, but without access to all the files it is difficult know where to start looking for the root of the cause for the the disconnect.

    Look at the first 8 lines of ... /web/filestore/index.php and see if there are clues, then work your way back through any files mentioned in those 8 lines.

  18. #18
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks everyone for all your help, I shall look into it all in the ways you've advised.

    If all else fails, I'll move hosting and make sure I check the servers details before I try writing this kind of thing again.

    Thanks again.

  19. #19
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I think you are best doing that.

    Even when solved, you still face the struggle of rewriting mysqli calls to mysql, which would depend on how many there are and how they are peppered through the application.

    The include problem might persist though - come back if it does and there are other diagnostics you can do to identify the next steps.

  20. #20
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by oldfruitanting View Post
    but they said that since it is a shared server they can't change setting like that, since they would have an effect on other sites hosted on the servers.
    I'm no server expert, but this bit puzzles me. I always thought mysql and mysqli were an AND AND, not an OR OR? I mean, enabling/installing/whatever the mysqli extension doesn't mean the mysql extension doesn't work anymore, does it? So installing it should have no effect at all on other sites? Or am I completely wrong here?

  21. #21
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Neither am I, but since PHP5 the plain old mysql functions had to be specifically downloaded and installed (with quite a bit of pain as I recall - on win32 anyhow), and mysqli and PDO (and drivers) were the bundled mechanisms - is my recollection.

    To make sure, try running:
    PHP Code:
    <?php
    print_r 
    (get_loaded_extensions());
    on a blank page, and see if it is there.

  22. #22
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oldfruitanting View Post
    Hi,
    I have done, but they said that since it is a shared server they can't change setting like that, since they would have an effect on other sites hosted on the servers.

    The hosts are Namesco, so I assumed they would be using up to date hardware/software!
    Find a new host - they're incompetent. They should have your account and the other sites hosted on the servers in their own VM's, leaving you free to pick your own OS, let alone what version of PHP you want to run. They have no excuse - doing things the old way exposes your data to exploits and malware that hits any of the sites in the shared hosting solution.

  23. #23
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    A 2 year old thread, resuscitated by a (now deleted) self promotion post.
    Thread closed.


Bookmarks

Posting Permissions

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