PHP error: Warning: ociparse() parameter 1 to be resource - php

As there is not ready made function in oracle to validate the Query so created.
So I tried below code to check whether the QUERY is valid or not.
if(isset($_POST['btn_Submit_Query']))
{
$check_query=$_POST['txtQuery'];
echo $check_query;
$valid = false;
$stmt = oci_parse($DB, $check_query);
echo "Statement" . $stmt;
//oci_define_by_name($stmt, 'NUMBER_OF_ROWS', $number_of_rows);
oci_execute($stmt, OCI_DEFAULT);
echo oci_num_rows($stmt);
}
I got following Warnings in the Execution:
Warning: oci_parse() expects parameter 1 to be resource, object given in D:\xampp\htdocs\app\DashBoardSite\Admin\querybuilder.php on line 899
Statement
Warning: oci_execute() expects parameter 1 to be resource, null given in D:\xampp\htdocs\app\DashBoardSite\Admin\querybuilder.php on line 902
Warning: oci_num_rows() expects parameter 1 to be resource, null given in D:\xampp\htdocs\app\DashBoardSite\Admin\querybuilder.php on line 903
Where is my mistake?

You must first connect to the database. This connection must a "resource" to variable $DB.

Related

imap_open() works locally but not on server

The issue is i'm trying to get the last email from my email using php, and it works fine locally. But then I uploaded the script to the client's server, and I don't get a response. When I check the logs, I get this:
[12-Feb-2020 08:43:21 location] PHP Warning: imap_open(): Couldn't open stream {<mail>:143/imap}INBOX in /path/triggerCall.php on line 2
[12-Feb-2020 08:43:21 location] PHP Warning: imap_headers() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 7
[12-Feb-2020 08:43:21 location] PHP Warning: imap_num_msg() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 14
[12-Feb-2020 08:43:21 location] PHP Warning: imap_header() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 16
[12-Feb-2020 08:43:21 location] PHP Warning: imap_fetchbody() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 20
[12-Feb-2020 08:43:21 location] PHP Warning: imap_close() expects parameter 1 to be resource, boolean given in /path/triggerCall.php on line 40
This is the code:
$inbox = imap_open('{<mail>:143/imap}', '<username>', '<password>');
$headers = imap_headers($inbox);
$last = imap_num_msg($inbox);
$header = imap_header($inbox, $last);
$body = imap_fetchbody($inbox, $last,1);
I have tried:
{<mail>:993/imap/novalidate-cert}INBOX
{<mail>:995/pop3/tls}INBOX
{<mail>:995/pop3/ssl}INBOX
{<mail>:993/imap/ssl}INBOX
{<mail>:110/pop3}INBOX
{<mail>:993/imap/tls/novalidate-cert}INBOX
{<mail>:143}INBOX
But none of those approaches work. Any ideas?
Try this
$inbox = imap_open('{mail.gmail.com/ssl/novalidate-cert}INBOX', 'email', 'password');
$mailbox = {outlook.office365.com:993/imap/ssl}.INBOX;
$this->mbox = imap_open($mailbox,USERNAME, PASSWORD, OP_READONLY) or die("can't connect: " . imap_last_error());

Why php crashes when writing and opening a file?

how the php is making error while opening and writing to the file.
function makeImage() {
$encoded_string = $_POST['encoded_string'];
$decoded_string = base64_decode($encoded_string);
$path = "C:\Inetpub\vhosts\apbclt.com\httpdocs\php\logo".$_POST['company_name'];
$file = fopen($path, 'wb');
$is_written = fwrite($file, $decoded_string);
fclose($file);
if($is_written > 0) {
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO Companies (logo) VALUES (?)");
$stmt->bind_param("s", $path);
$stmt->execute();
$stmt->store_result();
if($stmt->affected_rows > 0) {
$stmt->close();
return true;
}else{
$stmt->close();
return false;
}
}
}
and here is the error
PHP Warning: fopen(C:\Inetpubhosts\apbclt.com\httpdocs\php\logo): failed to open stream: Invalid argument in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 54
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 55
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 56
I searched SO but no answer to my case.
Update ::
when I changed the \v to \v like the first answer i got the following error.
PHP Warning: fopen(C:\Inetpub\vhosts\apbclt.com\httpdocs\php\logo): failed to open stream: Permission denied in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 54
PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 55
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in C:\Inetpub\vhosts\apbclt.com\httpdocs\php\create_company.php on line 56
ok I solved the issue instead of using the full file path I just used the path by going back a folder ..\logo

Php call to member function query() on a non-object error

I'm using mysqli for a function, and I'm getting an error, Fatal error: Call to a member function query() on a non-object in /home/u250000297/public_html/forum/system/db.php on line 46 I've tried different things, but I just get different errors, what am I doing wrong and where is my error?
Code lines 45-51:
function fetch($query) {
$sql = $mysqli->query($query);
$result = $sql->fetch_array(MYSQLI_BOTH);
return $result;
$sql->free();
}
Here's my previous attempt and error : Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 46 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 47 Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/u250000297/public_html/forum/system/db.php on line 46 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 47
Code, lines 45-51:
function fetch($query) {
$sql = mysqli_query($mysqli, $query);
$row = mysqli_fetch_array($sql, MYSQLI_BOTH);
return $row;
mysqli_free_result($row);
}
Connection:
$mysqli = mysqli_connect($this->host,$this->username,$this->password);
mysqli_select_db( $mysqli,$this->database );
if ($mysqli->connect_error) {
trigger_error('Database connection failed: ' . $mysqli->connect_error, E_USER_ERROR);
}
Either you need to define $mysqli as global or pass it as an argument.
After a return, no statement will be executed (mysqli_free).
Global:
function fetch($query) {
global $mysqli;
$sql = $mysqli->query($query);
$result = $sql->fetch_array(MYSQLI_BOTH);
return $result;
}
Parameter (and even better):
function fetch($myslqi, $query) {
$sql = $mysqli->query($query);
$result = $sql->fetch_array(MYSQLI_BOTH);
return $result;
}
Points to debug are
1) Is the connection to the database getting established?
2) Are your query strings correct?
Call to a member function query() on a non-object and Warning: mysqli_query() expects parameter 1 to be mysqli means that the $mysqli is null or isn't initialized properly. To get more information check the mysql error logs.

Php error when using mysqli

I've decided to using mysqli instead of mysql and I've having some errors, this is my first time using mysqli and I don't know what the errors are, any suggestions?
Warning: mysql_query() expects parameter 2 to be resource, string given in /home/u250000297/public_html/forum/system/db.php on line 45
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 45
Warning: mysql_query() expects parameter 2 to be resource, string given in /home/u250000297/public_html/forum/system/db.php on line 45
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/u250000297/public_html/forum/system/db.php on line 45
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u250000297/public_html/forum/system/db.php on line 33
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/u250000297/public_html/forum/system/db.php on line 33
Line 32-36
function query($query) {
$sql = mysqli_query($query, $this->db) or die(mysqli_error());
return $sql;
mysqli_free_result($sql);
}
Line 44-48
function fetch($query) {
$sql = mysqli_fetch_array(mysql_query($query, $this->db));
return $sql;
mysqli_free_result($sql);
}
Try this, You have used mysql_query instead of mysqli_query
function query($query) {
$sql = mysqli_query($this->db, $query) or die(mysqli_error());
...
}
function fetch($query) {
mysqli_fetch_array(mysqli_query($this->db, $query));
....
}
instead of
function fetch($query) {
mysqli_fetch_array(mysql_query($query, $this->db));
...
}
Try using a mysqli_query() function like this maybe
$data = mysqli_query($dbc, $query);
mysqli_fetch_array($data)
Notice that with mysqli_query() two arguments are passed:
the database connection variable
the query variable
Then use the the result of the mysqli_query() function as the argument to mysqli_fetch_array() function :D

mysqli prepared expect parameter?

I try to write own database class.I have some problem.
When I run it , it gives these errors.
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 75
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 76
Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 77
Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, boolean given in /Users/emrecetin/www/ayrox/m/db.php on line 78
on these line;
mysqli_stmt_bind_param($sor, 's', $hede);
mysqli_stmt_execute($sor);
mysqli_stmt_bind_result($sor, $bas);
mysqli_stmt_fetch($sor);
I will give short version of databse class.It is not exactly, I write just what I use.
class db{
public $durum;
protected $server = 'localhost';
protected $suser = 'root';
protected $spass = 'root';
public $db = 'members';
public $durum; // mysqli durumu
public $sor; // mysql_query ile birleştirilen hali
public $kacsonuc;
function db(){
$this->durum = mysqli_connect($this->server,$this->suser,$this->spass);
$this->dbchoose($this->db)
}
function dbchoose($db){
if(!mysqli_select_db($this->durum,$db)){
$this->errors[] = 'Database cant choose';
$this->hata=True;
}
function see(){
$id = 'select * from uyeler where id=?';
$sor = mysqli_prepare($this->durum, $id);
$hede = '3';
mysqli_stmt_bind_param($sor, 's', $hede);
mysqli_stmt_execute($sor);
mysqli_stmt_bind_result($sor, $bas);
mysqli_stmt_fetch($sor);
}
}
what is the problem ? I cant understand.Thank you (and sorry for my grammer).
Anytime you see "boolean given" in a mysql error message, it means that some previous mysql function call has failed, returning a boolean FALSE value. You're trying to use that boolean false in the current mysql call, and get this message.
You have no error handling in your code, which means those FALSE values will propagate throughout your code, spitting out those errors everywhere it goes.
At minimum, your code should look something like this, everywhere you do a mysql/mysqli call:
function see(){
$id = 'select * from uyeler where id=?';
$sor = mysqli_prepare($this->durum, $id);
if ($sor === FALSE) {
die(mysqli_error($this->durm));
}
etc...
}
How you handle the error is up to you - in this case it'll simply abort the script and tell you why.

Categories