MySQLI Fatal Error in production but not development [duplicate] - php

This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
I have this code:
$mysqli = new mysqli('localhost','username','password','database');
$insert = "INSERT INTO submissions ( client_name, client_company ) VALUES ('$client_name', '$client_company' )";
if ( $mysqli->query($insert) === TRUE ) {
echo "success";
} else {
echo "Error: " . $mysqli . "<br>" . $mysqli->error;
}
In my development environment it runs perfectly, inserting the variables into the correct table columns.
However in production I get this error:
Catchable fatal error: Object of class mysqli could not be converted
to string in 'path' on line x
I know that:
There is no error with my mysqli connection as the rest of my application uses the credentials etc. fine to retrieve data from my db in both dev/live
That this code runs fine, inserts correctly, doesn't error in my dev environment.
I've looked for solutions to the Error message- and have tried a few, but I remain unconvinced that this is the actual cause for the issue.

PHP try to cast $mysqli to string here:
echo "Error: " . $mysqli . "<br>" . $mysqli->error;
You should do that like this instead
echo "Error: with mysqli <br>" . $mysqli->error;
Or maybe a var vump if you want more details but mysqli->error should be enough

Related

My task is about PHP connectivity with xampp server which is not connecting and giving me erroe [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Kindly show me the error in my code i am trying to connect the sign in form with database using php but i am getting these errors:
Warning: mysqli_connect(): (HY000/1045): Access denied for user
'root'#'localhost' (using password: YES) in
C:\xampp\htdocs\MyProject\php\signin.php on line 9
Notice: Trying to get property of non-object in
C:\xampp\htdocs\MyProject\php\signin.php on line 11
Fatal error: Uncaught Error: Call to a member function query() on
boolean in C:\xampp\htdocs\MyProject\php\signin.php:17 Stack trace: #0
{main} thrown in C:\xampp\htdocs\MyProject\php\signin.php on line 17
<?php
$servername = "localhost";
$username = "root";
$password="";
$dbname = "myproject";
// Create connection
$conn = mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO sign_in (username,password)";
if ($conn->query($sql) === TRUE) {
echo "New record inserted successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
You are getting this ERROR because of your is mixed up with mysqli_* functions and PDO code.
Methods of both PDO connection and mysqli_* are different.
Here is your error.
******Here is your error*****
$sql = "INSERT INTO sign_in (username,password)";
if ($conn->query($sql) === TRUE) { //ERROR line
echo "New record inserted successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
You have use function mysqli_query() instead of accessing member function of $conn, just take below correct example.
// Perform queries
mysqli_query($conn,"SELECT * FROM Persons");
mysqli_query($conn,"INSERT INTO Persons (FirstName,LastName,Age) VALUES ('Glenn','Quagmire',33)");
mysqli_close($conn);
Hope you get the point and will help you..
There must be a password on root mysql account that you're not providing here:
$password="";
Other parts of the error is a direct consequence of this, $conn became a boolean and not an object as the mysqli_connect() is unsuccessful (it gives back false on failure).
Your query is not correct, since no values where given to insert. It should look like this:
$sql = "INSERT INTO sign_in (username,password) VALUES ($username,$password)";

php error on my error_log while posting [duplicate]

This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 6 years ago.
this is my php codes getting Post Successfully response when true but when it failed for some reason.
i got this error.
mysqli_error() expects parameter 1 to be mysqli, null given
$result = mysqli_query($connection, $query) ;
if($result){$response["msg"] = "Post Successfully";
echo json_encode($response);} else {$response["msg"] = "failed ".mysqli_error($con);
echo json_encode($response);
}
mysqli_close($connection);
}
$con is null
mysqli_error($con); should be mysqli_error($connection); as you have declared connection as $connection.
According to this line:
mysqli_query($connection, $query)
You are using variable $connection for link identifier, and in mysqli_error($con) you are using $con variable which is undefined or NULL, this should be:
mysqli_error($connection)

Is there any know issue with PHP 5.3.29 and $stmt->get_result() function? [duplicate]

This question already has answers here:
Fatal error: Call to undefined method mysqli_stmt::get_result() [duplicate]
(2 answers)
Closed 7 years ago.
I have mysqli script, Unfortunately it doesn't run on my Server with PHP 5.3.29.
As far as I can debug the server doesn't return any value for the function get_result() and the script breaks after it. Is there any know issue?
$query = "SELECT * FROM test WHERE column = ? LIMIT 1";
$stmt = $mysqli->stmt_init();
if(!$stmt->prepare($query)) echo "Failed to prepare statement\n";
else echo "prepare statement okay\n";
if(!$stmt->bind_param('s', 'test')) echo "Failed to bind parameter\n";
else echo "bind parameter okay\n";
if(!$stmt->execute()) echo "Failed to execute\n";
else echo "execute okay\n";
$result = $stmt->get_result();
if(!$result) echo "Failed to get result \n";
else echo "result okay\n";
The output would be just:
prepare statement okay
bind parameter okay
execute okay
Any ideas?
You are getting the following error:
PHP Fatal error: Call to undefined method mysqli_stmt::get_result()
The error message does not leave any room for doubt: You're calling a method that does not exists.
Looking up the method in question in the PHP manual shows this detail:
Available only with mysqlnd.
So it's not only the PHP version you need to fulfil but also a specific mysql driver.

How to debug mysqli_query? [duplicate]

This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 8 years ago.
I have a connection to my database:
$con=mysqli_connect("localhost","xxxx","xxxxx","xxxxxx");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
which returns no error.
I then try to perform a mysqli_query:
$result = mysqli_query($con,"INSERT INTO entries (name, genre, info , date , website , twebsite, video , tvideo, image, extra_genre)
VALUES ('".$name."', '".$type."', '".$info."', '".$date."', '".$url."', '".$href."', '".$_POST["video"]."', '".$videotype."', 'video images/".$photo."', '".$type2."')");
with the alert whether this insertion to the database has worked or not:
if($result)
{
echo "Success:";
}
else
{
echo "error inserting data into database: ";
}
When I perform my code I get the output error inserting data into database:
But I have no ides why $result is not successful?
How can I debug it?
You are looking for mysqli_error() function.
Problem here is that date is a reserved word, so you have to escape that: `date`
try this:
echo $result;
and then run the sql output.. that should give you an error message.

mysqli_error() is not working [duplicate]

This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 3 years ago.
I have written a mysql_query and it is not working.
I want to know the problem via mysqli_error() however it gives the following error mysqli_error() expects parameter 1 to be mysqli
my mysql code is as follows:
$connect = mysqli_connect("localhost","root", "", "tomuman");
$query = mysqli_query($connect, "SELECT id, to FROM messages WHERE read='0'");
and mysqli_error as follows:
echo mysqli_error($query);
What could cause this problem?
You should not use $query as a parameter for mysqli_error()
use
echo mysqli_error($connect);
Just after trying to connect you can also check for specific connection errors with:
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}
Add following code in your query to get the mysql error message.
or die (mysqli_error($connect))
as like below
$query = mysqli_query($connect, "SELECT id, to FROM messages WHERE read='0'") or die (mysqli_error($connect));
if ($query) {
echo "success";
}
else {
echo("Error description: " . mysqli_error($connect));
}

Categories