Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1133 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Time to update my MySQL into MySQLi =(

Thread title: Time to update my MySQL into MySQLi =(
Reply    
    Thread tools Search this thread Display Modes  
08-17-2012, 07:29 PM
#1
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old  Time to update my MySQL into MySQLi =(

http://pastebin.com/ehJi20n9

I've attempted to update these functions several times, but I keep getting thrown errors.

Does anyone have a MySQLi database class I could peak at? Or better yet, give me a few starting points on what to change in my own code.

08-17-2012, 07:35 PM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Classes like these are usually unnecessary with MySQLi, they have their own set of functions and they don't really need to be abstracted a step further.

Also, query sanitization is not an issue because MySQLi uses parameters.

08-17-2012, 08:39 PM
#3
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

I figured using a class will save me from editing every file. In theory I can just edit my db class.

hmmph

Reply With Quote
08-17-2012, 08:49 PM
#4
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

I don't think there is a direct conversion because mysql queries from the depreciated library are built as a string then sent while mysqli uses parameters. Parameters send the variables at a later time than the query, so your queries might look like

"SELECT something FROM a_database WHERE something=? and something_else=?"

You'd send that to the database then tell it to bind those two variables before you actually execute it. This makes SQL injection literally impossible and is a lot faster. If you are just building a query like you would have before you may as well not convert.

08-18-2012, 09:58 AM
#5
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Originally Posted by Dan View Post
I figured using a class will save me from editing every file. In theory I can just edit my db class.
It depends what you're doing outside of the class. For example, calling that escape() method is not needed if you change to using prepared statements where the query itself and the input parameters are separated.

It looks fairly trivial (you can keep the external API the same) to take your existing class and make it use MySQLi instead.

The changes would be things like the way errors are handled (looking at error properties rather than a false return value), the fetch_*() methods are slightly different for MySQLi, and (if you want it) adding in prepared statement support to your query() method.

09-10-2012, 01:58 PM
#6
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

I'm not that interested in prepared statements at the moment, I just want this wrapper updating to MySQLi so once MySQL becomes depreciated I haven't got to update a billion websites.

Here is my attempt at updating it:

http://pastebin.com/f77k3VJG

However it chucks all sorts of errors:


Warning: mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO) in /home/count/Workspace/lib/classes/user.php on line 7 Warning: mysql_query(): A link to the server could not be established in /home/count/Workspace/lib/classes/user.php on line 7 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/count/Workspace/lib/classes/user.php on line 8 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in /home/count/Workspace/lib/classes/database.php on line 32

Reply With Quote
09-10-2012, 05:07 PM
#7
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Those are all resulting form the connection error. Figure out why it isn't connection and it should work. I'd start by hard coding the permissions into the function and working backwards with the variables, it's probably something small.

Reply With Quote
09-12-2012, 05:01 PM
#8
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Thanks. Figured it out.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed