473,287 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

mysqli: prepared statements and fetch_array method?

I'm rewriting a database interface that our company currently has.
Currently it's using the Pear::DB interface, but we found that that was
introducing a bit too much overhead. I'm rewriting the interface to use
mysqli. Most of what the interface does is to simplify getting results in
the form of arrays (ordered and associative). Most of the code using the
interface used sql queries with placeholders and parameters. For that
reason I'd like to use prepared statements in mysqli, but I'm running into
a few problems.

The mysql_result object has a fetch_array method that I'd like to use, but
as far as I can tell it doesn't appear that prepared statements (the
mysqli_stmt class) even uses the mysql_result class. It appears that,
with prepared statements, you must bind variables to the mysqli_stmt
object with bind_result, which causes the statement to set those variables
when you use it's fetch() method. The mysqli_result object can only be
obtained (as far as I can see) using the mysqli_query method with an
unprepared query. (Please let me know if I'm mistaken on this.)

That's were I ran into a more significant problem. When variables are
bound to the statements results, mysqli attempts to convert them to the
appropriate php data types, and I can't find any way to prevent it from
doing so. This makes it impossible to select large integers (larger than
the php integer size) into string variables. mysqli always tries to
convert them to integers and this of course wraps. The existing code
using my interface simply has to have the ability to do this...changing
the underlying SQL to cast columns or the like isn't an option.

Interestingly, the mysqli_result fetch_array method appears to select
everything as strings, much like the old mysql interface. I would prefer
that, as I have code in my interface to do data conversions if and when I
need to. But again, I see no way of using this with prepared statements.

Unless I'm mistaken on this I may have to scrap using prepared statements
altogether and emulate prepared statements by parsing and replacing the
queries placeholders myself (much like pear does) which I'd rather avoid.

Thanks in advance for any suggestions!

Tom
Aug 29 '05 #1
1 3781
On Mon, 29 Aug 2005 18:05:50 -0400, Tom D <no***@nowhere.com> wrote:
I'm rewriting a database interface that our company currently has.
Currently it's using the Pear::DB interface, but we found that that was
introducing a bit too much overhead. I'm rewriting the interface to use
mysqli. Most of what the interface does is to simplify getting results in
the form of arrays (ordered and associative). Most of the code using the
interface used sql queries with placeholders and parameters. For that
reason I'd like to use prepared statements in mysqli, but I'm running into
a few problems.


This isn't a direct answer, it's one of those annoying "you're doing X with Y
but have you looked at Z" answers: if overhead was the main issue, have you
compared it with ADOdb? It fares quite well in benchmarks, particularly when
compared with PEAR which seems to do quite badly.

ADOdb emulates prepared statements for older versions of MySQL, but also has
mysqli support which from a glance at the code does use mysqli_stmt_bind_param,
so is using native prepared statements.

Can't comment as to whether it would solve the other issues, though.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Aug 29 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark | last post by:
hello! mysqli in PHP5 comes with prepared statements functionality. However, without persistent connections or connection pooling in this code library, one has to ask: why bother? are...
1
by: webguynow | last post by:
I'm trying to build a good DB Layer on top of Pear::DB Are there any forums or knowledge base sites on this direct topic ? I've been using the documentation at:...
26
by: Dodger | last post by:
Okay, background... yes, I am another of those evil, spurned, damnable Perl mongers, but I'm not trying to start a flamewar, I'm juust tryung to understand something... I can write a script in...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
12
by: davids58 | last post by:
trying to figure out how to use a mysql database with PHP. I ran the following code: <?php // defines database connection data define('DB_HOST', 'localhost'); define('DB_USER', 'ajaxuser');...
4
by: sugapablo | last post by:
I have a website that I was moving from another server to mine for somebody. This website uses mysqli functions. mysqli extensions are installed on my Linux server, PHP is 5.1.6 and and MySQL...
11
by: macca | last post by:
Hi, What should I be using for general MySQL database access? I've been using the traditional mysql extension for ages, but I'm trying to update my style to a more OOP paradigm. I've used...
1
by: lazukars | last post by:
I have done a good amount of research on prepared statements in php. The problem is that I have found various examples on how to select and insert information into a Mysql database. I want to make...
0
by: lazukars | last post by:
I am building some code with msqli prepared statements via. The code will be used for a form that will send data to a MySql database. What I would like to know is how secure are prepared...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.