This question already has answers here:
Call to undefined method mysqli_stmt::get_result
(10 answers)
Closed 3 years ago.
I moved my php code to a new hosting which missing mysql_nd and a have more than 150 functions that use stmt->get_result() and fetch_assoc.
Is there a function that can do the same work of stmt->get_result() and fetch_assoc and give the exact results so I can fix the problem without having to modify all the functions?
You have two choices.
The first is to contact your provider indicating that you need MySql Native Driver.
The second is to review all your code as a PDO or alternatively MySqli (PDO Council).
In terms of time, with the second option we invest a little more, but for sure you will make your application more stable and secure. I would personally use it for the second hypothesis.
Related
This question already has answers here:
MySQL and PDO: Could PDO::lastInsertId theoretically fail?
(2 answers)
Closed 7 years ago.
I am hoping to not have to write another request to mysqli to get the id of an inserted row.
I need to know if PDO::lastInsertId is an asynchronous thread safe method.
Since this is a functionality question, i will provide a schematic instead of a library i wrote that handles PDO; However, I will provide if necessary.
SCHEMATIC
$connect = mysqli->connect
$is_inserted = $connect->insert(...)
if($is_inserted){
$last_insert_id = $connect->lastInsertId();
}
I need to make sure that a another user will not get someone elses insert_id if they are running the script simultaneously.
The docs for LAST_INSERT_ID() say:
For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client.
So, you should have no issues using $connect->lastInsertId().
This question already has answers here:
How to change mysql to mysqli?
(12 answers)
Closed 1 year ago.
I want to switch from MySQL to MySQLi, but I have a very large website.
I read that https://wikis.oracle.com/display/mysql/Converting+to+MySQLi could help me and I read How could I change this mysql to mysqli?. It says that I could replace most of the functions with just adding an 'i' to the function, and that I should start bughunting.
But my website is very complex and large, and it would take a very long time to check if everything works. So: what is the best way to switch from MySQL to MySQLi for a very large website?
Thanks!
There is no easy answer to your question as practically every simple way to do this involved doing things differently when the application was written.
If you have direct calls to mysql_* functions throughout your code and no database abstraction layer where you do your queries through a helper class or function then you will need to edit every command.
You cannot just get away with adding an i to commands like mysql_query as procedurally mysqli_query() requires the first parameter to be the link to the db where with mysql_query() if a connection was given at all, it was a second parameter.
Instead of just changing mysql_query(...) to mysqli_query($link,.....) I would recommend that there is no better time to put a db abstraction layer in place. So use functions eg sql_query() that actually process your queries so in future if you need to change DB again you can just update the db specific commands in one abstraction file. That way if you write a function that wraps mysqli_query then you could be able to simply rename your mysql_query() to your helper function and let the helper function worry about putting the link in there.
Whilst that is the simplest way, it will not bind parameters or prepare statements which is a major factor in preventing sql injection vulnerabilities
Once you have changed all these commands you need to test.
If you have no automated tests written then this is probably a good time to start writing them. Even though you will need to check that every change has worked, if you do it by automated test then you can avoid that pain in future.
you are taking right move becouse the mysql_* function are deprecated for latest php version. you should download a converter for this purpose...
see this and download...mysql to mysqli
This question already has answers here:
How to send a SQL query to database in PHP without waiting for result
(3 answers)
Closed 9 years ago.
Firstly I'm using the deprecated mysql functions (instead of mysqli) knowingly, so please do not tell me I should change to mysqli.
My question is: if I want to do an INSERT or UPDATE and continue processing the PHP script immediately, without waiting for MySQL to complete the task, can I use mysql_unbuffered_query (is that what is does?) or if not, how can I achieve that?
Sorry to break this to you :)
If you use mysqli, with the mysqlnd driver, you can pass a MYSQLI_ASYNC option to the query() method. Unbuffered queries do not help here.
Later on you can use the poll() and reap_async_query() to get to the result.
You can use INSERT...DELAYED for asynchronous insertions (1). I do not believe you can do asynchronous UPDATE's without resorting to spawning another process (2).
(1) but is not available to InnoDB tables
(2) if sticking to the old mysql extension is an absolute requirement
This question already has answers here:
PHP: multiple SQL queries in one mysql_query statement
(4 answers)
Closed 8 years ago.
These two PHP MySQL queries work.
mysql_query("DELETE FROM videos WHERE id='10';");
mysql_query("DELETE FROM comments WHERE videoId='10';");
This single query fails due to a MySQL syntax error pertinent to the latter DELETE operation.
mysql_query("DELETE FROM videos WHERE id='10';DELETE FROM comments WHERE videoId='10';");
I've stared hard and can't see the syntax error. What is it?
Not supported by mysql_query see How can I put two queries in one mysql_query? use http://docs.php.net/mysqli.multi-query
You cannot execute multiple queries with mysql_query. If you really want to (security risk!), use mysql_multi_query. (And you should use the newer mysqli_* functions). It's a good idea two embed those two calls in a transaction.
But this looks a lot like you really want to define foreign key constraints. I highly recommend them, if you are already using InnoDB.
Multiples queries are not supported in this function.
http://php.net/manual/en/function.mysql-query.php
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Performing simple arithmetic in MySQL statement or in PHP code
Im wondering what is the best to use, from point of view performance:
PHP functions (to calculate a date in the future) and to input the date in the DB query
MYSQL function (to calculate a date in the future) e.g. TIMESTAMPADD(DAY,3,UTC_DATE()) directly inside the query
If you're manipulating dates in a table, it's definitely better to use MySql functions. This is particularly true if the mySql server might be accessed by different hosts (which might not have their clocks all synchronized with each other).