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:

  Quote
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.

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();

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);

 

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.