473,554 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!

Aug 29 '05 #1
1 3800
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_bin d_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.u k :: 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

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 prepared statements 'remembered' by the server for a while between connections, so that new connections can take advantage of them, or are they really...
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: http://pear.php.net/package/DB/docs But since I'm not always online, is there a way I can download this ? Or if the documentation is derived from the classes, How can I build...
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 Perl like so, and it's pretty to me (and the using of the heredocs I think does defend perl against many arguments withthe HTML being all escaped and...
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 querys. (where you only change the parameters) But what if you do only ONE query; will it then be usefull to use prepared statements? Can it actuelly give...
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'); define('DB_PASSWORD', 'practical'); define('DB_DATABASE', 'ajax'); // connect to the database $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD,...
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 is 4.1.22 (both higher than his server). All seems to work fine, but any statement that uses the bind (i.e. placing a ? in the sql statement, and...
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 PDO briefly but I've not used the mysqli extension yet. I've read a bit about it though, seems good and more OOP orientated (for the most part). But...
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 sure that I am doing this correctly. Could anyone please show post a correct example of how to SELECT data from mysql via prepared statements via...
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 statements? If there are any vulnerabilities, what are they?
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.