Questions tagged [mysqli]
The mysqli PHP extension is a PHP database driver. Not to be confused with MySQL database.
25,044
questions
342
votes
13
answers
145k
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
230k
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.
146
votes
1
answer
61k
views
How to deal with mysqli problems? mysqli_fetch_array(): Argument #1 must be of type mysqli_result
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 ...
128
votes
4
answers
119k
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?
122
votes
10
answers
146k
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(...
116
votes
25
answers
339k
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);
...
113
votes
4
answers
16k
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
23
answers
243k
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 = ...
100
votes
11
answers
11k
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
18
answers
263k
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.
89
votes
4
answers
108k
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 ...
87
votes
15
answers
227k
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 ...
82
votes
8
answers
408k
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 ...
77
votes
3
answers
133k
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:
$...
75
votes
12
answers
183k
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 ...
74
votes
6
answers
110k
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)
...
73
votes
2
answers
99k
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(...
66
votes
14
answers
256k
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, ...
64
votes
2
answers
260k
views
How to display errors for my MySQLi query? [duplicate]
I am using the following script to process a form to add info to my website. The problem I am having is when I submit the form nothing gets submitted to the database, and there are no errors. How can ...
60
votes
5
answers
113k
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?
58
votes
3
answers
63k
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"...
57
votes
19
answers
312k
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 ...
56
votes
10
answers
60k
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
14
answers
331k
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 ...
55
votes
16
answers
312k
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 ...
55
votes
3
answers
47k
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 ...
53
votes
6
answers
57k
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
6
answers
95k
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);...
52
votes
11
answers
103k
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 ...
49
votes
1
answer
59k
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 ...
49
votes
12
answers
64k
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 ...
48
votes
1
answer
459k
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 ...
45
votes
4
answers
113k
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 ...
44
votes
4
answers
156k
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 ...
44
votes
5
answers
61k
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 ...
43
votes
4
answers
113k
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 publisher@example.com
This is the code I'm ...
41
votes
4
answers
38k
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 ...
41
votes
3
answers
52k
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 ...
40
votes
1
answer
51k
views
How to insert into MySQL using a prepared statement with PHP [duplicate]
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 ...
39
votes
6
answers
145k
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.
<?...
39
votes
4
answers
184k
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 ...
37
votes
4
answers
53k
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
6
answers
25k
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 ...
36
votes
1
answer
39k
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
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 ...
35
votes
6
answers
93k
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. (...
35
votes
4
answers
187k
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 * ...
35
votes
8
answers
104k
views
Single Value Mysqli [duplicate]
I am trying to write a function that will check for a single value in the db using mysqli without having to place it in an array. What else can I do besides what I am already doing here?
function ...
35
votes
2
answers
18k
views
PHP and MySQLi close()
I am new to MySQL and PHP and am attempting to make my own CMS to help make managing my websites easier. Can someone explain mysqli's close() function?
Is it necessary?
What exactly does it do?
I ...
34
votes
4
answers
52k
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 ...