Jump to content

Query Empty when trying to Insert into database (odbc connection)


chum1215

Recommended Posts

Hi, I hope you guys can help me out. I only know basic PHP and also SQL.  I haven't tried using connecting database yet.

 

My problem is that I'm trying to INSERT a data into an existing table using access but when it reaches $rs = odbc_exec(); it returns an error that the query was empty.

 

Here is the code:

$conn=odbc_connect('trial','','');
if (!$conn)
  {exit("Connection Failed: " . $conn);}
$sql = "INSERT INTO Data (FirstName, LastName, BusinessName) 
VALUES ('$fname', '$lname', '$bname')";

$rs=odbc_exec($sql, $conn);

$rs = @odbc_exec($conn,$sqlstring);

if (!$rs)
{
echo "An error has occured. Please try again", odbc_errormsg($conn);
}
else
{
echo "The record was successfully inserted.";
}

odbc_close($conn);

 

 

and here is the error:

An error has occured. Please try again[MySQL][ODBC 5.1 Driver][mysqld-5.5.20]Query was empty

 

 

I really hope you could help me out.

 

Thanks.

Link to comment
Share on other sites

first make sure that php_oci8 is enabled.

 

define('SCHEMA', 'system');

define('PASSWORD', 'yourpassword');

define('DATABASE', 'localhost/XE');

define('CHARSET', 'UTF8');

 

 

class connect_database {

 

public $conn = '';

public function __construct() {

 

$this->conn = @oci_connect(SCHEMA, PASSWORD, DATABASE, CHARSET);

 

if (!$this->conn) {

$m = oci_error();

throw new \Exception('Cannot connect to database: ' . $m['message']);

}

 

}

 

}

 

global $connectdb;

$connectdb = new connect_database();

Link to comment
Share on other sites

before executing parse it.

 

$sql="select * from person";

$s = oci_parse($connectdb->conn,$sql);

if (!$s) {

$m = oci_error($c);

trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);

}

$r = oci_execute($s);

if (!$r) {

$m = oci_error($s);

trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);

 

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.