mysqli

PHP + MYSQLI: Variable parameter/result binding with prepared statements.

In a project that I'm about to wrap up, I've written and implemented an object-relational mapping solution for PHP. Before the doubters and dreamers cry out "how on earth?", relax -- I haven't found a way to make late static binding work -- I'm just working around it in the best way that I possibly can. Anyway, I'm not currently using p...

mysqli or PDO - what are the pros and cons?

In our place we're split between using mysqli and PDO for stuff like prepared statements and transaction support. Some projects use one, some the other. There is little realistic likelihood of us ever moving to another RDBMS. I prefer PDO for the single reason that it allows named parameters for prepared statements, and as far as I am a...

Using MySQLi - which is better for closing queries

I have a habit of keeping my variable usage to a bare minimum. So I'm wondering if there is any advantage to be gained by the following: $query = $mysqli->query('SELECT * FROM `people` ORDER BY `name` ASC LIMIT 0,30'); // Example 1 $query = $query->fetch_assoc(); // Example 2 $query_r = $query->fetch_assoc(); $query->free(); Now if...

PHP + MySql + Stored Procedures, how do I get access an "out" value?

Documentation is severely lacking on anything to do with stored procedures in mysql with PHP. I currently have a stored procedure that I call via PHP, how can I get the value of an out parameter? ...

mysqli_statement::num_rows() returns the wrong value

I was writing a database handler class in PHP using the mysqli class and prepared statements. I was attempting to print out the result. It didn't work right off the bat so I decided to do some debugging. I tried to use the num_rows() method from the mysqli_statement class, but it kept returning 0. I decided to write a small porti...

Possible to use multiple/nested MySQLi statements?

Is it possible to have a MySQLi prepared statement within the fetch() call of a previous statement? If not, what's the best way around it? Example code: if($stmt = $link->prepare("SELECT item FROM data WHERE id = ?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($item); while( $stmt->fetch() ) { /* ...

Which is fastest in PHP- MySQL or MySQLi?

I'd like to know if anyone has any first-hand experience with this dichotomy. A few blogs say the mysql extension is faster than mysqli. Is this true? And I'm only asking about speed. I know mysqli has features that are not present in the older extension. ...

Empty string in not-null column in MySQL?

I used to use the standard mysql_connect(), mysql_query(), etc statements for doing MySQL stuff from PHP. Lately I've been switching over to using the wonderful MDB2 class. Along with it, I'm using prepared statements, so I don't have to worry about escaping my input and SQL injection attacks. However, there's one problem I'm running in...

Is there a way to bind an array to mysqli prepare

I'm trying to make a class that will execute any one of a number of stored procedures with any amount of variables Im using php and mysqli My class enumerates an array and constructs a string based on the number of elements if any giving something like this CALL spTestLogin(?,?) for example I now need to bind the input from my array u...

Is there a way to see a prepared query as it will be executed on the database?

I'm using the mysqli extension in PHP and I'm wondering, is there possibly any way to see a prepared query as it will be executed on the server, e.g. The query is something like this select * from table1 where id = ? and name = ? but I want to see the query after the values are filled in, like this: select * from table1 where id = 20...

mysqli->error: Is it for the last query only, or for the last error from the query group?

Hi All, I am new to mysqli, and trying to confirm that if I so something like the below, the errno will be set to the last error, if any, and not the error of the last query. Is this a decent practice or should I be checking for the error in between every query? Thanks! $mysqli->autocommit(FALSE); $mysqli->query("INSERT INTO ........

Do MySQL prepared queries provide a performance benefit for once-per-session queries?

According to the documentation, a prepared query provides a significant performance benefit if you're running a query multiple times because the overhead of the MySQL server parsing the query only happens once. I'm wondering what exactly they mean by "multiple times" there. I.e., say you have a web page that runs a query one time. Now s...

using nulls in a mysqli prepared statement

In a mysqli prepared statement, a NULL gets turned into '' (in the case of a string) or 0 (in the case of an integer). I would like to store it as a true NULL. Is there any way of doing this? ...

mysqli prepared statements and REPLACE INTO

I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table the REPLACE INTO query works just fine, however if PHPSESSID exists the call to execute succeeds but sqlstate is set to 'HY000' which isn't very helpful and $_mysqli_session_write->errno and $_mysqli_session_write-...

Ensuring MySQL connection works in PHP function

I have code with the following form: <?php function doSomething{ //Do stuff with MySQL $con->tralalala(); } $con = connectToDatabase;//This would actually be a line or two. doSomething(); ?> This (type of) code doesn't work, because doSomething() doesn't have a connection to the database. Can anyone explain why not? I create the...

Getting a PHP DateTime object into a string representation of a MYSQL date

I have a DateTime which I want to store in a Date MySQL column. I am using MySQLi and prepared statements. When binding parameters, I cannot specify date as a type, only strings and integers. How do I convert the DateTime to a MySQL date string representation? There is very little documentation on the DateTime class. ...

Limit a MySQL query to an even number of results (using PHP and mysqli)

Hi, I have a bit of PHP code which I need to return an even number of results from a MySQL database. I'm using the mysqli extension to execute my query. My code is approximately this at the moment: //assume we already have a database connection $query = "SELECT id FROM movies WHERE publish = 1 AN...

The counterpart of mysqli::real_escape_string?

stripslashes() ? That's lame and so 4.0. What's the 5.0 counterpart of mysqli::real_escape_string that strips all slashes added for SQL queries? Got some other questions: Tried to update a record and added a single quote in a text field, turns out phpMyAdmin escapes the string with single quotes instead of slashes - e.g. a single quot...

converting from mysql to mysqli - outputting variables

I have been using the mysql api in PHP, and am now converting to mysqli for the increased security. The example syntax I have seen uses printf, and I would like to know if this is necessary. At the moment I use echo, like so: echo "<h1>".$row['ARTICLE_NAME']."</h1> <div id='leftlayer' class='leftlayer'> <p><strong>Username: </strong>".$...

php giving a blank page, no errors

Hello, I have the following part of an AJAX application, which gives no errors, but also nothing is displayed to the screen, so I am unsure of where the problem lies. Calling this page directly from a browser with ?cmd&id=1 should return, or even calling it without ?cmd should return the cmd error message. edit: added test cases: I do ...