HOME > PHP > PHP Forum > foxpro, php : error => odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified...
foxpro, php : error => odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified...
odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002
ส่วนของ User DSN กับ System DSN ก็มี Microsoft Visual FoxPro Driver ติดตั้งแล้ว ทั้งแบบ 86x และ 64x เคยได้ทำเสร็จไปแล้วแต่พออัพเป็น php 7 กลับไม่ได้ php.ini ก็ เพิ่ม php_odbc.dll แล้ว เลยไม่รู้ว่าข้ามส่วนไหนไปครับ
connect.php
class VFPConnect {
var $dsn;
var $conn;
function __construct($db=""){
$this->dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=".$db.";";
$this->dsn .= "Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$this->conn = odbc_connect($this->dsn,'','');
}
}
class VFPConn {
var $conn;
var $rs;
function __construct($db_path,$sql){
$this->conn = (new VFPConnect($db_path))->conn;
$this->rs = odbc_exec($this->conn,$sql) or die("connect fail");
}
function close(){
odbc_close($this->conn);
}
}
<?php
$objConnect = odbc_connect("mydatabase","sa","") or die("Error Connect to Database");
$strSQL = "SELECT * FROM customer";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
?>