This is with php , PDO on MS Access .mdb with linux drivers , have this code :
$sql = "SELECT * FROM F_ART WHERE CODART = :id";
$result = $this->cache->get($sql . $id);
if(!$result){
$stm = $this->db->prepare($sql);
$stm->bindParam(':id',$id);
$stm->execute();
$result = $stm->fetchAll();
$this->cache->set($sql.$id,$result);
}
return $result;
which output this:
Error at Line : syntax error near ?
syntax error near ?
Got no result for 'SELECT * FROM F_ART WHERE CODART = ?' command
with normal query string it works :
$sql = "SELECT * FROM F_ART WHERE CODART ='" . $id . "'";
$result = $this->cache->get($sql . $id);
if (!$result) {
$result = $this->db->query($sql)->fetchAll();
$this->cache->set($sql.$id,$result);
}
return $result;
where is the problem?
Related
I've been receiving this error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'schoolPass = '300570'' at line 1.
please help here is my code for login.php.
<?php
session_start();
require_once '../cn.php';
require_once '../functions.php';
if (isset($_POST['email']) && ($_POST['password'])){
$email = sanitizeString($_POST['email']);
$pass = sanitizeString($_POST['password']);
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' schoolPass = '$pass'";
$result = mysqli_query ($conn, $query) or die (mysqli_error($conn));
$count = mysqli_num_rows ($result);
if ($count == 1) {
echo "pwede na";
} else {
$err = "Invalid Log in Credentials";
};
if (isset($_SESSION['email'])){
$email = $_SESSION['email'];
echo ("hello.$email.");
};
} else {
echo "email/ password not set";
};
$conn->close();
?>
Replace your code line:
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' schoolPass = '$pass'";
BY
$query = "SELECT schoolEmail,schoolPass FROM schools WHERE schoolEmail =
'$email' AND schoolPass = '$pass'";
$query = "
SELECT schoolEmail
, schoolPass
FROM schools
WHERE schoolEmail = '$email'
AND schoolPass = '$pass'
";
In between your two conditions on WHERE, it should be separated by an AND or an OR or a NOT.
what i need to fetch data from stored procedures
syntax in sql developer
select abc_web_demo.wwv_json_data.dashboards('abc','7','tt',1211) from dual
returns json string
{"data":[{"logs":7,"to_abc":88,"to_cl":12,"to_me":0}]}
code
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =ABC)(PORT = 1521))
)
(CONNECT_DATA = (SID = AAA))
)
";
try {
$conn = new PDO("oci:dbname=".$tns, '**', '**');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Connected to database';
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
$sql = "CALL abc_web_demo.wwv_json_data.dashboards('ABC','79','Y',121221) ";
$stmt = $conn->prepare($sql);
$te=$stmt->execute();
//$stmt = $connection->query("SELECT #NEW_ID");
//$id = $stmt->fetchColumn();
print_r($te);
Problem
i have google & found i need to pass in string in query
like $stmt = $connection->query("SELECT #NEW_ID");
here in my my case i need to pass 4 parameters in procedure.
i new in stored procedures i need help how to pass 4 arguments in procedure .
how to access json response using fetch statement.
i need json repsonse from fetch data.
any help much appreciated
Solution i tried
$output = $conn->query("select 'abc', '7' ")->fetch(PDO::FETCH_ASSOC);
var_dump($output);
Error
SQLSTATE[HY000]: General error: 923 OCIStmtExecute: ORA-00923: FROM keyword not found where expected
when i tried test query it works
$stmt = $conn->prepare("select * from customers");
$st=$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($result);
Write your query as follows. The FROM clause is mandatory in Oracle dialect of SQL.
select 'abc', '7' from dual
<?php
echo "Hello test <br>";
$userid = $_GET['userid'];
echo "your user userid is " . $userid . " &";
$salt = $_GET['salt'];
echo " your user salt is " . $salt;
// Query for finding the data from db
// Issue in query
$sql = "SELECT * FROM test.test where id=" .$userid AND "salt=".$salt;
echo "<br>" . $sql;
$result = $conn->query($sql);
if (!empty($result))
{
echo "<br>Result Found";
}
else
{
echo "<br> Invalid link !";
}
// }
?>
My Query is not working properly. If I reduce my query to id=".$userid it works properly but if I add remaining portion its not working.
The $sql line should be:
$sql = "SELECT * FROM sauberlux_com.tbl_b2cuser where id=".$userid." AND salt=".$salt;
$sql = "SELECT * FROM sauberlux_com.tbl_b2cuser where id = $userid AND salt = $salt";
Try it.
$sql = "SELECT * FROM sauberlux_com.tbl_b2cuser where id = $userid AND salt = '$salt' ";
Also you can refer here for sql injection
this my model code:
function get_ads($page=0, $type, $limit=1, $order=' order by rand()') {
if ($page === 0) {
$page = $this->get_adpage();
$qry = "select * from tbl_ads ";
$qry .= " where status=1 and pages like '%".$page. "%'";
$qry .= " and type = ".intval($type);
$qry .= $order;
$qry .= intval($limit) > 1 ? " limit 0,".$limit : " limit 0,1";
$results = $this->db->query($qry)->result(); return $results;}
}
}
Query like this
SELECT * FROM tbl_ads WHERE STATUS=1 AND pages LIKE '%1%' AND TYPE = 1 ORDER BY RAND() LIMIT 0,1`
Controller code is
function get_ads(){
$this->main_model->get_ads(14,2,1);
}
Its working fine local when uploading to server showing fatal error some times but some times its working fine.
Thanks for your help
Here the solution
$this->db->query($qry)->result() in this instead of result() result_array() for multiple rows or row_array() for single row of result did the trick
I'm simply trying to run a query using wpdb query and prepare statements.
On my page it returns:
[You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'myQuery' at line 1]
PHP Code:
<?php
$dirName1 = 'C:/wamp/www/c2c/wp-content/themes/flawless-v1-01';
$dirName2 = 'C:/wamp/www/c2c';
require_once($dirName1.'/config/setup.php');
require_once($dirName2.'/wp-config.php');
require_once($dirName2.'/wp-load.php');
$wpdb->show_errors();
$tableName = $wpdb->prefix . "user_orders";
$user = wp_get_current_user();
$userId = $user->ID;
$userName = $user->user_login;
// echo $tableName . ': ' . $userId . ': '. $userName;
// echo var_dump($tableName);
// echo var_dump($userId);
// echo var_dump($userName);
// These echo the correct formats for the prepare statement below
$myQuery = $wpdb->query(
$wpdb->prepare("
SELECT *
FROM $tableName
WHERE `user_id` = %d
AND `user_name` = %s",
$tableName,
$userId,
$userName)
);
$results = $wpdb->get_results(myQuery, ARRAY_A);
?>
You're missing the dollar sign before your variable name:
$results = $wpdb->get_results(myQuery, ARRAY_A);
should be
$results = $wpdb->get_results($myQuery, ARRAY_A);