Nubie problems - Converting mysqli to mysql?


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.


Why not just ask the host to use mysqli?
You really should really find a host that is running at minimum PHP 5.3.

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!

“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)


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.

From the sounds of it, you have a WPSE problem. Take a look at the Common PHP Errors thread, try what’s in there.

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.

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/ [function.include-once]: failed to open stream: No such file or directory in /content/Hosting/a/l/ on line 8

Warning: include_once() [function.include]: Failed opening ‘/content/Hosting/a/l/’ for inclusion (include_path=‘.:/usr/local/fphp5/lib/php’) in /content/Hosting/a/l/ on line 8

Warning: mysql_set_charset() expects parameter 1 to be string, resource given in /content/Hosting/a/l/ on line 10

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

Warning: include(output.html.php) [function.include]: failed to open stream: No such file or directory in /content/Hosting/a/l/ 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/ on line 13

Sorry, I did say I was a noobie.


Your includes contain both the “.html” and “.php” extensions. You only need the “.php”

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.

Do you have a copy of this working on your local development machine, or is all the code on your live server?

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.

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.

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.

On your local site, what have you got listed against this line in your php.ini file:


// live server contains this apparently :



Is this what you mean?!

; UNIX: “/path1:/path2”
;include_path = “.:/php/includes”
; Windows: “\path1;\path2”
;include_path = “.;c:\php\includes”


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.


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.

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.

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?