chum1215 Posted May 8, 2012 Share Posted May 8, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262232-query-empty-when-trying-to-insert-into-database-odbc-connection/ Share on other sites More sharing options...
Pikachu2000 Posted May 8, 2012 Share Posted May 8, 2012 $sql != $sqlstring Quote Link to comment https://forums.phpfreaks.com/topic/262232-query-empty-when-trying-to-insert-into-database-odbc-connection/#findComment-1343858 Share on other sites More sharing options...
sanjay_zed Posted May 8, 2012 Share Posted May 8, 2012 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(); Quote Link to comment https://forums.phpfreaks.com/topic/262232-query-empty-when-trying-to-insert-into-database-odbc-connection/#findComment-1343871 Share on other sites More sharing options...
sanjay_zed Posted May 8, 2012 Share Posted May 8, 2012 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); } Quote Link to comment https://forums.phpfreaks.com/topic/262232-query-empty-when-trying-to-insert-into-database-odbc-connection/#findComment-1343873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.