Questions tagged [mysqli]
The mysqli PHP extension is a PHP database driver. Not to be confused with MySQL database.
24,956
questions
342
votes
13
answers
150k
views
mysqli or PDO - what are the pros and cons? [closed]
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 ...
171
votes
6
answers
232k
views
MySQL vs MySQLi when using PHP [closed]
Which is better, MySQL or MySQLi? And why? Which should I use?
I mean better not just in terms of performance, but any other relevant feature.
159
votes
1
answer
75k
views
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
In my local/development environment, the MySQLi query is performing OK. However, when I upload it on my web host environment, I get this error:
Fatal error: Call to a member function bind_param() on ...
131
votes
10
answers
155k
views
Call to undefined method mysqli_stmt::get_result
Here's my code:
include 'conn.php';
$conn = new Connection();
$query = 'SELECT EmailVerified, Blocked FROM users WHERE Email = ? AND SLA = ? AND `Password` = ?';
$stmt = $conn->mysqli->prepare(...
130
votes
26
answers
408k
views
How to solve "Fatal error: Class 'MySQLi' not found"?
I am doing a tutorial and am getting this error:
Fatal error: Class 'MySQLi' not found (LONG URL) on line 8
The code on line 8 is:
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);
...
129
votes
4
answers
124k
views
What is the difference between MySQL, MySQLi and PDO? [closed]
What is the difference between MySQL, MySQLi and PDO?
Which one is the best suited to use with PHP-MySQL?
125
votes
24
answers
280k
views
Commands out of sync; you can't run this command now
I am trying to execute my PHP code, which calls two MySQL queries via mysqli, and get the error "Commands out of sync; you can't run this command now".
Here is the code I am using
<?php
$con = ...
118
votes
4
answers
17k
views
Can I mix MySQL APIs in PHP?
I have searched the net and so far what I have seen is that you can use mysql_ and mysqli_ together meaning:
<?php
$con=mysqli_connect("localhost", "root" ,"" ,"mysql");
if( mysqli_connect_errno( ...
111
votes
19
answers
307k
views
mysqli_real_connect(): (HY000/2002): No such file or directory
mysqli_real_connect(): (HY000/2002): No such file or directory
PhpMyAdmin error on MacOS. I want answer I really have no idea what I need to do to resolve this.
100
votes
11
answers
12k
views
Do I have to guard against SQL injection if I used a dropdown?
I understand that you should NEVER trust user input from a form, mainly due to the chance of SQL injection.
However, does this also apply to a form where the only input is from a dropdown(s) (see ...
95
votes
12
answers
331k
views
On a function that gets settings from a DB I ran into the error [duplicate]
I'm busy on a function that gets settings from a DB, and suddenly, I ran into this error:
Fatal error: Call to a member function bind_param() on boolean in C:\xampp2\htdocs\application\classes\class....
94
votes
14
answers
242k
views
Headers and client library minor version mismatch
In PHP I'm getting the following warning whenever I try to connect to a database (via mysql_connect)
Warning: mysql_connect(): Headers and client library minor version mismatch. Headers:50162 ...
93
votes
8
answers
479k
views
How can I enable the MySQLi extension in PHP 7?
I have installed PHP 7 and MySQL 5.5.47 on Ubuntu 14.04 (Trusty Tahr).
I have checked installed extension using:
sudo apt-cache search php7-*
It outputs:
php7.0-common - Common files for ...
90
votes
4
answers
115k
views
Example of how to use bind_result vs get_result
I would like to see an example of how to call using bind_result vs. get_result and what would be the purpose of using one over the other.
Also the pro and cons of using each.
What is the limitation ...
85
votes
3
answers
148k
views
MySQLi prepared statements error reporting [duplicate]
I'm trying to get my head around MySQli and I'm confused by the error reporting.
I am using the return value of the MySQLi 'prepare' statement to detect errors when executing SQL, like this:
$...
82
votes
7
answers
134k
views
Warning: mysqli_connect(): (HY000/2002): No such file or directory
I'm trying to install vanilla forums on my Mac, and for this I just created a database and a user from the MySQL command line:
mysql> CREATE DATABASE vanilla;
Query OK, 1 row affected (0.00 sec)
...
81
votes
12
answers
197k
views
How to change mysql to mysqli?
Based on this code below I use for regular mysql, how could I convert it to use mysqli?
Is it as simple as changing mysql_query($sql); to mysqli_query($sql);?
<?PHP
//in my header file that is ...
80
votes
16
answers
318k
views
Fatal error: Call to undefined function mysqli_connect()
For 2 days now I'm trying to solve this, but unfortunately no result. Let me tell you my story about the problem. I've bulid an application on a site, and the application deals with the reviews. But, ...
74
votes
2
answers
108k
views
PHP error: "Cannot pass parameter 2 by reference"
I just need help on this PHP error which I do not quite understand:
Fatal error: Cannot pass parameter 2 by reference in /web/stud/openup/inactivatesession.php on line 13
<?php
error_reporting(...
70
votes
21
answers
450k
views
phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO)
I keep getting the following errors with mysql connection through XAMPP and I don't know what to do:
That's the code in the config.inc.php
<?php
/*
* This is needed for cookie based ...
64
votes
5
answers
126k
views
Using Mysqli bind_param with date and time columns?
How do you insert data into a MySQL date or time column using PHP mysqli and bind_param?
62
votes
3
answers
54k
views
Using Prepared Statement, how I return the id of the inserted row?
I want retrieve the id of a inserted row in the database, but I don't know how to do this.
I tried to return using the SQL clause RETURNING id, but not works.
How I can return the id after the ...
59
votes
2
answers
68k
views
How can I with mysqli make a query with LIKE and get all results?
This is my code but it dosn't work:
$param = "%{$_POST['user']}%";
$stmt = $db->prepare("SELECT id,Username FROM users WHERE Username LIKE ?");
$stmt->bind_param("s"...
58
votes
15
answers
366k
views
CodeIgniter: Unable to connect to your database server using the provided settings Error Message
I have been using CI just fine using the MySQL driver. I want to use the MySQL driver instead, but as soon as I change it (just add the ‘i’ at the end of MySQL, and added the port number) I get the ...
56
votes
6
answers
105k
views
$stmt->execute() : How to know if db insert was successful?
With the following piece of code, how do i know that anything was inserted in to the db?
if ($stmt = $connection->prepare("insert into table (blah) values (?)")) {
$stmt->bind_param("s", $blah);...
56
votes
10
answers
61k
views
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 ...
55
votes
16
answers
316k
views
How to install MySQLi on MacOS
I cannot find instructions about installing MySQLi on a Mac. Just to be clear, MySQL is up to date and I am running PHP 5. How do I install it? Where do I even get it from? Thanks for your help. I'll ...
53
votes
6
answers
63k
views
How to echo a MySQLi prepared statement?
I'm playing around with MySQLi at the moment, trying to figure out how it all works. In my current projects I always like to echo out a query string while coding, just to make sure that everything is ...
52
votes
11
answers
108k
views
mysqli fetch_all() not a valid function?
Thanks to the answers I have figured out that I am unable to use fetch_all() because i am using PHP 5.2.17 - fetch_assoc with while loop worked.
The function I am using fetch_all is coming back with ...
52
votes
1
answer
63k
views
PHP MySQLI Prevent SQL Injection [duplicate]
I've build a website that will be going live soon and just have a couple questions about preventing SQL injection, I understand how to use mysqli_real_escape_string but I'm just wondering if I have to ...
51
votes
12
answers
69k
views
MySQLi equivalent of mysql_result()?
I'm porting some old PHP code from mysql to MySQLi, and I've ran into a minor snag.
Is there no equivalent to the old mysql_result() function?
I know mysql_result() is slower than the other ...
49
votes
1
answer
481k
views
mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in [duplicate]
I'm have some trouble checking if a Facebook User_id already exists in my database (if it doesn't it should then accept the user as a new one and else just load the canvas application). I ran it on my ...
49
votes
4
answers
121k
views
How to check if a row exists in MySQL? (i.e. check if username or email exists in MySQL)
I need help checking if a row exists in the database. In my case, that row contains an email address. I am getting the result:
email no longer exists [email protected]
This is the code I'm ...
48
votes
4
answers
169k
views
mysqli::query(): Couldn't fetch mysqli
Warning: mysqli::query(): Couldn't fetch mysqli in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\my portable files\class_EventCalendar.php on line 43
The following is my connection ...
46
votes
4
answers
121k
views
MySQLi count(*) always returns 1
I'm trying to count the number of rows in a table and thought that this was the correct way to do that:
$result = $db->query("SELECT COUNT(*) FROM `table`;");
$count = $result->num_rows;
But ...
46
votes
5
answers
66k
views
How to start and end transaction in mysqli?
As far as I understood transaction starts once we call $mysqli->autocommit(FALSE); statement and ends after calling $mysqli->commit(); command like in the example below.
<?php
//Start ...
46
votes
6
answers
165k
views
Single result from database using mysqli
I am trying to use mySQLi for the first time. I have done it in the case of loop. Loop results are showing but I am stuck when I try to show a single record. Here is loop code that is working.
<?...
42
votes
4
answers
40k
views
MySQLi query results: When do I close, free, or both?
I have some questions about using MySQLi queries, and related memory management.
Suppose I have something like this:
$db = new mysqli($dbhost, $un, $ps, $dbname);
$query = "SELECT field1, field2 ...
42
votes
3
answers
59k
views
new mysqli vs mysqli_connect
What is difference between the new mysqli and mysqli_connect?
I know that executing a query is different;
for example: mysqli->query() and mysqli_query()
Why are there two different types, what ...
42
votes
1
answer
54k
views
How to insert into MySQL using mysqli
I am just learning about databases and I want to be able to store user inputs. What would be a basic example on how to get form data and save it to a database using PHP?
Also making the form secure ...
40
votes
6
answers
54k
views
MySQLi not found dockerized php
I'm trying to dockerize my website. I've got Nginx and PHP up and running and it's working find except I can't connect to a db. When the page is loaded I get the error:
Fatal error: Uncaught Error: ...
40
votes
4
answers
56k
views
mysqli or die, does it have to die?
If I use a bit of code like this:
$update_result = mysqli_query( $link , $sql_update_login ) or die ('Unable to execute query. '. mysqli_error($link));
Does it have to die or can you put a ...
40
votes
3
answers
22k
views
mysqli_store_result() vs. mysqli_use_result()
The question
What is the difference between mysqli::store_result() and mysqli::use_result()?
The story
Vague documentation
The documentation on PHP.net seems very vague about the difference ...
39
votes
4
answers
193k
views
How to call a MySQL stored procedure from within PHP code?
I have stored procedure that I created in MySQL and want PHP to call that stored procedure. What is the best way to do this?
-MySQL client version: 4.1.11
-MySQL Server version: 5.0.45
Here is my ...
39
votes
6
answers
26k
views
PHP PDO and MySQLi [duplicate]
I just finished an introduction course in PHP, and throughout the stackoverflow forum people have recommended that I switch to PDO, prepared statements or MYSQLi, I briefly checked the manual but most ...
38
votes
6
answers
101k
views
How to convert mysqli result to JSON? [duplicate]
I have a mysqli query which I need to format as JSON for a mobile application.
I have managed to produce an XML document for the query results, however I am looking for something more lightweight. (...
37
votes
4
answers
55k
views
mysqli - Do I really need to do $result->close(); & $mysqli->close();?
Just started using mysqli. If I'm working with small data sets on small websites (traffic-wise), do I really need to use these all the time?
$result->close();
$mysqli->close();
Also, for ...
37
votes
1
answer
43k
views
bind_param Number of variables doesn't match number of parameters in prepared statement
Here is a snippet from my code:
$stmt = $mysqli->prepare("SELECT DISTINCT model FROM vehicle_types
WHERE year = ? AND make = '?' ORDER by model");
$stmt->bind_param('is', $year, $...
36
votes
5
answers
197k
views
mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket 'MySQL' (2)
I get this error when I try to connect to the mysql database using php mysqli class. Using following code:
$db = new MySQLi("localhost","kamil","*****");
password is * ...
36
votes
7
answers
55k
views
How can I bind an array of strings with a mysqli prepared statement?
I need to bind an array of values to WHERE IN(?) clause. How can I do that?
This works:
$mysqli = new mysqli("localhost", "root", "root", "db");
if(!$mysqli || $...