This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 1 year ago.
I want to retrieve all data from a table, so I use this code
<?php
include("config.php");
$sql = "SELECT * FROM ".$USERS;
$sql_result = mysqli_query($connection, $sql);
if ($sql_result) {
while ($result = mysql_fetch_assoc($sql_result)) {
echo $result;
}
}
else {
die ('Could not execute SQL query '.$sql);
}
?>
but got this warning:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource,
object given in C:\xampp\htdocs\newSDP\phpscript\users.php on line 6
How can I fix it?
Change:
mysql_fetch_assoc to mysqli_fetch_assoc
Related
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 6 years ago.
I have a line of code in my php that reads:
$sel_venue = "SELECT 'char_type' FROM 'character_type_allowed' WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue);
while ($row = mysqli_fetch_array($run_venue))
if ($row['char_type'] == 'Mortal')
{ print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>"); }
The link associated with this does nothing. Zero interaction beyond acting likeit wants to expand. My error log produces this: Why is it asking for this?
[08-Aug-2016 23:28:41 America/New_York] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/houchat/public_html/incl/creation.php on line 8
You can't use ' as ticks for field/tablenames.
Your query is producing an error. You can see the error with mysqli_error($con).
Please see the corrected code below
$sel_venue = "SELECT `char_type` FROM `character_type_allowed` WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($run_venue)) {
if ($row['char_type'] === 'Mortal') {
print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>");
}
}
Your query failed, so $run_venue is the boolean false instead of what you expect. You should check for errors before you use any query result. Do this:
$run_venue = mysqli_query(...);
if(!$run_venue) die(mysqli_error($con));
... //<- we get here if the query succeeded
You will see the error. The problem is that your SQL statement wraps the table name between single quotes 'character_type_allowed', instead of backticks (backtick is above the tab key on my keyboard)
This question already has answers here:
php mysqli query expects parameter 1 be to string
(2 answers)
Closed 6 years ago.
I am getting this error:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs
My code:
function dbQuery($sql)
{
$result = mysqli_query($sql) or die(mysqli_connect_error());
return $result;
}
It's inside a function, MySQLi is not having access to your connection as far as I know.
If your database connection is named $conn, you can write it like:
function dbQuery($sql) {
global $conn;
$result = mysqli_query($conn, $sql) or die(mysqli_connect_error());
return $result;
}
Please read the manual on how to use mysqli_query: http://php.net/manual/en/mysqli.query.php. The correct way to use it is:
$result = mysqli_query($conn,$sql);
where $conn is your mysqli connection, and $sql is the query to run.
This question already has answers here:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in
(3 answers)
Closed 6 years ago.
There have been lots of posts about this and crawled them all but can't figure out why im getting this message. I am not good with SQl and this coding so really hope someone can help.
A customer can checkout and order fine but after Sagepay always presented with the above error message. (line 70 in bold below)
$query="SELECT surname, town, county, country, currencyID, goodsTotal, shippingTotal, taxTotal, discountTotal FROM $tableOrdersHeaders WHERE orderID = '$myOrderID' AND randID = '$myRandID' LIMIT 1";
**$result = mysqli_query($query) or die( "Unable to retrieve order details");**
$num_results = mysqli_num_rows($result);
if ($num_results > 0){
// build the array from the results
$ga_order = mysqli_fetch_array($result, MYSQL_ASSOC);
} else {
die( "No matching order found");
Now the DB access file for SQLI code I believe it uses is
function connect($sql_host_name,$sql_username,$sql_password,$sql_database_name) {
$this->currentDatabase = $sql_database_name;
$this->resID = #mysqli_connect($sql_host_name,$sql_username,$sql_password);
if ($this->resID == FALSE) {
$this->lastError = "Could not connect to mySQL server";
return FALSE;
} else {
if (#mysqli_select_db($this->resID, $sql_database_name)) {
return TRUE;
} else {
return #mysqli_query($this->resID,"create database $sql_database_name");
return FALSE;
Really hope someone can help.
If you are using the procedural style of mysqli functions, you mysqli_query needs the connection variable as the first argument, followed by the query string.
It looks like you are just giving it the query string on here: $result = mysqli_query($query) or die( "Unable to retrieve order details");.
You'll want something like: $result = mysqli_query($connection, $query).
Reference: http://php.net/manual/en/mysqli.query.php
This question already has answers here:
sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in
(3 answers)
Closed 7 years ago.
It is not dublicated question. im trying print records from my db (IIS, MSSQL PHP) but i have this error...
<?php
require_once 'connection.php';
$uspCall_Actividades="call usp_SelectCountActividades()";
/*Executando el query*/
$rsActividad=sqlsrv_query($connection1,$uspCall_Actividades);
while ($objRs=sqlsrv_fetch_object($rsActividad)){
echo($objRs->cantidad);
}
?>
Error: Warning: sqlsrv_fetch_object() expects parameter 1 to be resource, boolean
Change:
$uspCall_Actividades="call usp_SelectCountActividades()";
to use {} brackets:
$uspCall_Actividades="{call usp_SelectCountActividades()}";
You should also always wrap the while in a check
if($rsActividad === false) {
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
} else {
while (...) {
...
}
}
Also specify any parameters you need:
$params = array(
array($text, SQLSRV_PARAM_OUT)
);
$rsActividad=sqlsrv_query($connection1,$uspCall_Actividades,$params);
This question already has an answer here:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
(1 answer)
Closed 8 years ago.
Im receiving the following error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
$getholidays isnt the result of getholidayrequest()
or
from the documentation:
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query
you should check the mysql_query return value
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
die('RequĂȘte invalide : ' . mysql_error());
}