This question already has answers here:
PHP - Using PDO with IN clause array
(9 answers)
Why does this PDO statement silently fail?
(2 answers)
Closed 3 years ago.
I have a little problem with my SQL query:
I have a variable ($arraySearch) with a string:
$arraySearch = "'Bob', 'Ross'";
My PHP query:
$stmt = $this->pdo->prepare("SELECT * FROM `kunden` WHERE `FAMNAME` IN (arraySearch =:arraySearch) AND `VORNAME` IN (arraySearch = :arraySearch)");
$stmt->execute(['arraySearch' => $arraySearch]);
$all = $stmt->fetchAll(PDO::FETCH_CLASS, $model);
Error Code:
Fatal error: Uncaught Error: Call to a member function execute() on boolean
I've been searching for the error for hours but I can't find it.
What am I missing?
Does somebody have any idea?
best regards
Related
This question already has answers here:
Call to a member function execute() on boolean in [duplicate]
(5 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 1 year ago.
I am trying to SELECT data from 1 database and insert into another, but I have problem in INSERT.
I get this error PHP Fatal error: Uncaught Error: Call to a member function execute() on boolean when I run my code.
MY CODE
<?php
include 'db_acc.php';
include 'db_sat.php';
$sql = "SELECT created_at,updated_at
FROM satellite1.show_activity";
$result=$conn1->query($sql);
while($row = $result->fetch_assoc()) {
echo "$row[updated_at]"; // I can get the value
$sql2 = "INSERT INTO analysis_account.currency SET
id=0,
currency_code='MYR',
currency_rate= 3.500,
currency_unit= 100,
base_currency= 1,
created_by= 2,
updated_by= 2,
created_at= '2021-05-17 14:10:32',
updated_at = ".$row["updated_at"].", // But I cant insert the value
curr_hidden = 1 ";
$query=$conn2->query($sql2);
}
$conn2->close();
?>
The problem is I can get the value of $row[updated_at] but I cant insert it into other database table, the connection is no problem because if I change $row[updated_at] into '2021-05-17 14:10:32' then the insert statement work.
I checked my connection, column names, symbols there are no problem of them. I really dont know what to do to solve the error.
Your INSERT query is missing quotes around the timestamp value. Just change
updated_at = ".$row["updated_at"].",
to
updated_at = '".$row["updated_at"]."',
This would fix the insert functionality but your code remains susceptible to SQL injection attacks. Please avoid simple string concatenation in your SQL queries and prefer prepared statements with placeholders.
This question already has answers here:
How to include a PHP variable inside a MySQL statement
(5 answers)
Closed 2 years ago.
Hej.
I get this error message when execute my code? I post value "2020-12-19" $data_input_textfield = $_POST["date"]; from my form. cant figure out where 1989 comes from...
Message:
Exception has occurred.
PDOException: SQLSTATE[HY000]: General error: 1525 Incorrect DATE value: '1989'
The code:
$sql = "CALL booking_date_input($data_input_textfield)";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->execute();
$date=$stmt->fetch();
Best regards
/Svante
You can try a slightly different approach whereby you supply a placeholder to the sql command and execute the statement with the variable bound to that placehoolder - like so:
$sql = "CALL `booking_date_input`(:date);";
$stmt = $dbh->getInstance()->prepare($sql);
$stmt->execute(array(':date'=>$data_input_textfield));
$date=$stmt->fetch();
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 2 years ago.
I have been trying to do a DELETE statement and i even tried running the query in MySQL workbench and everything was ok but in my service it does't seem to accept it.
$statement_delete = $this->conn->prepare("DELETE FROM crm_suite_tcl.aos_products_quotes where parent_id = ?");
$statement_delete->bind_param("s", $id_pedido);
$statement_delete->execute();
$resultado_borrar_lineas = $statement_delete->get_result();
It throws that the statement is false, so it doesn't let me execute it
Fatal error: Call to a member function bind_param() on boolean in
Fatal error: Call to a member function bind_param() on boolean in C:\xampp2\htdocs\crm\service\sync\include\db_handler.php on line 210
The error you are getting basically means that your statement cannot be prepared most likely due to a syntax error (a column or table that doesn't exist).
Try adding in your code:
if(!$statement_delete){
error_log($this->conn->error);
}
This should write the error to the console and you will be able to correct it.
This question already has answers here:
PHP PDO - Bind table name? [duplicate]
(2 answers)
Can PHP PDO Statements accept the table or column name as parameter?
(8 answers)
Closed 4 years ago.
when I run the following:
$pdo = new PDO('sqlite:/path/to/database.db');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('CREATE TABLE IF NOT EXISTS :user (id INTEGER PRIMARY KEY AUTOINCREMENT, time INTEGER NOT NULL, ping TEXT NOT NULL);');
$user = "me";
$stmt->execute(array('user' => $user));
I get the following error, referencing the :user part of the SQL:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 near ":user": syntax error in /datasql.php:21\nStack trace:\n#0 /datasql.php(21): PDO->prepare('CREATE TABLE IF...')\n#1 {main}\n thrown in /datasql.php on line 21
I can't find anything wrong with the SQL and if I run the command without the variable insertion, it runs fine.
What is causing this error?
Thanks ahead!
This question already has answers here:
Call to a member function bind_param() on a non-object [duplicate]
(6 answers)
Closed 5 years ago.
$employee_stmt=$con->prepare("INSET INTO employee (emp_name, emp_desig, emp_salary, years_exp, emp_status, emp_adr, city, pin_code, emp_phone, emp_email, emergency_contact, emergency_phone, blood_group, known_health_issue)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$employee_stmt->bind_param('ssssssssssssss',$_POST['employee_name'],$_POST['designation'],$_POST['salary'],$_POST['exp'],$_POST['emp_status'],$_POST['address'],$_POST['city'],$_POST['pin'],$_POST['phone'],$_POST['emp_email'],$_POST['emr_contact'],$_POST['emr_phone'],$_POST['blood_group'],$_POST['health_issue']);
Looks like your statement can not be prepared. You should check SQL for errors. (For example in post INSET used instead of INSERT).