Hmm. I've found a code example, mind you from 2005 so it's probably out of date on its own... But I was wondering about it, and haven't been able to find it on PHP's document site.
I know using the ?'s is used in Prepared Statements, but I was wondering if this code block is still possible in current versions - $sql = 'INSERT INTO user (username,passwordHash) VALUES (?,?)';
-
$result = $db->query($sql, array($_POST['username'], $passwordHash));
Link. First code block. Link
not sure about MySQLi, but you can pass an array of parameters directly to PDOStatement->execute(), although this implies the values to be strings (i.e. as type parameter, PDO::PARAM_STR will be passed, regardless whether that is true for the data type or the DB field type)
and to answer the question directly, you can pass your values like the guy in the article, though that requires you to write the appropriate Database Abstraction Layer (classes).
4 1373
this code is at least nothing native to PHP, as both in MySQLi and PDO, Prepared Statements are invoked by ->prepare() and executed by ->execute(), you may bind the values before calling execute().
there is no information about the nature of the $db object (which is only meant for illustration), as the focus of the article was password hashing.
I understand, I was just hoping that I would be able to pass the parameters the way he did in his article. Thats all. Since my own searching did not reveal anything. I wanted to ask here in hopes someone could answer.
not sure about MySQLi, but you can pass an array of parameters directly to PDOStatement->execute(), although this implies the values to be strings (i.e. as type parameter, PDO::PARAM_STR will be passed, regardless whether that is true for the data type or the DB field type)
and to answer the question directly, you can pass your values like the guy in the article, though that requires you to write the appropriate Database Abstraction Layer (classes).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yzzzzz |
last post by:
Hi,
I am compiling PHP 5.0.2 myself with MySQL support.
I did a ./configure --with-mysqli=/usr/local/mysql/bin/mysql_config
(see end of post for complete configure)
Note: I also have...
|
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...
|
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...
|
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');...
|
by: Schmidty |
last post by:
If you do a page reload with $_SERVER will your program
lose a mysqli connection upon the reload of the page? Would this code
work? I need to know how to carry over a connection between methods as...
|
by: Schmidty |
last post by:
Okay...I have another 'newbie' question;
I have a function that loads a page and the action is
$_SERVER;
In the form that is in a function(method?) within a class a variable
is passed back to...
|
by: Daz |
last post by:
Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I...
|
by: webcm123 |
last post by:
People say that structural programming isn't good for database
connection. I code fast-running structural oriented CMS and I don't
know what I should do. I use mysql connection using mysql_*. I...
|
by: Michael |
last post by:
Hi,
I try to use mysqli object instead of standard mysql functions.
Is it ok to create mysqli object within my class or schould I pass
mysqli object to my object.
The problem is, with code...
|
by: Taras_96 |
last post by:
Hi everyone,
I'm trying to run a number of commands stored within a sql file from
within php using mysqli::query. The syntax I'm using is:
source C:\data\projects\forum...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |