Estoy revisando mi codigo, y al quere adaptarlo a otro servidor, tengo que modificar muchos archivo, y quiero simplificar esta tarea.
Este es el codigo que utilizo para mis consultas, y esta funcionando:
Código PHP:
Ver original
<?php include_once("../php/dbconfig.php"); $db = new DBConnection(); $db->getConnection(); $sql = "select idcatmatrix as id from catmatrix where idcatagencia='dk09a'"; echo $row->id; } ?>
Codigo de dbconfig.php:
Código PHP:
Ver original
<?php class DBConnection{ function getConnection(){ //change to your database server/user name/password //change to your database name } } ?>
Todo bien hasta aqui, ahora utilizo JTable, JTable, y cada tabla tiene su propio conexion a bd, ejemplo:
Código PHP:
Ver original
<?php try { //Open database connection //Getting records (listAction) if($_GET["action"] == "list") { //Get record count $recordCount = $row['RecordCount']; //Get records from database $result = mysql_query("SELECT idcatAgencia, idcatMatrix, Contra FROM CATMATRIX ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";"); //Add all records to an array { $rows[] = $row; } //Return result to jTable $jTableResult['Result'] = "OK"; $jTableResult['TotalRecordCount'] = $recordCount; $jTableResult['Records'] = $rows; } //Creating a new record (createAction) else if($_GET["action"] == "create") { //Insert record into database $result = mysql_query("INSERT INTO catmatrix (idcatMatrix, idcatAgencia, Contra) VALUES (" . $_POST["idcatMatrix"] . ", '" . $_POST["idcatAgencia"] . "', '" . $_POST["Contra"] . "');"); //Get last inserted record (to return to jTable) //Return result to jTable $jTableResult['Result'] = "OK"; $jTableResult['Record'] = $row; } //Updating a record (updateAction) else if($_GET["action"] == "update") { //Update record in database $result = mysql_query("UPDATE `catmatrix` SET `idcatAgencia`='" . $_POST["idcatAgencia"] . "', `Contra`='" . $_POST["Contra"] . "' WHERE `idcatMatrix`='" . $_POST["idcatMatrix"] . "';"); //Return result to jTable $jTableResult['Result'] = "OK"; } //Deleting a record (deleteAction) else if($_GET["action"] == "delete") { //Delete from database //Return result to jTable $jTableResult['Result'] = "OK"; } //Close database connection } catch(Exception $ex) { //Return error message $jTableResult['Result'] = "ERROR"; $jTableResult['Message'] = $ex->getMessage(); } ?>
lo que quiero es que una vez configurado mi archivo dbconfig, ya no tenga que configurar mas.
En el archivo donde esta mis consultas, trato de mander a traer mi configuracion quedando asi:
Código PHP:
Ver original
<?php include_once("../php/dbconfig.php"); include_once("../php/functions.php"); $db = new DBConnection(); $db->getConnection(); $sql = "select idcatmatrix as id from catmatrix where idcatagencia='dk09a'"; echo $row->id; } ?>
lo pruebo y me imprime el resultado esperado. Pero al querer implimentarlo con mis consultas, me manda error:
Código PHP:
Ver original
<?php include_once("../php/dbconfig.php"); include_once("../php/functions.php"); $db = new DBConnection(); $db->getConnection(); try { //Open database connection //Getting records (listAction) if($_GET["action"] == "list") { //Get record count $recordCount = $row['RecordCount']; //Get records from database $result = mysql_query("SELECT idcatAgencia, idcatMatrix, Contra FROM CATMATRIX ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";"); //Add all records to an array { $rows[] = $row; } //Return result to jTable $jTableResult['Result'] = "OK"; $jTableResult['TotalRecordCount'] = $recordCount; $jTableResult['Records'] = $rows; } //Creating a new record (createAction) else if($_GET["action"] == "create") { //Insert record into database $result = mysql_query("INSERT INTO catmatrix (idcatMatrix, idcatAgencia, Contra) VALUES (" . $_POST["idcatMatrix"] . ", '" . $_POST["idcatAgencia"] . "', '" . $_POST["Contra"] . "');"); //Get last inserted record (to return to jTable) //Return result to jTable $jTableResult['Result'] = "OK"; $jTableResult['Record'] = $row; } //Updating a record (updateAction) else if($_GET["action"] == "update") { //Update record in database $result = mysql_query("UPDATE `catmatrix` SET `idcatAgencia`='" . $_POST["idcatAgencia"] . "', `Contra`='" . $_POST["Contra"] . "' WHERE `idcatMatrix`='" . $_POST["idcatMatrix"] . "';"); //Return result to jTable $jTableResult['Result'] = "OK"; } //Deleting a record (deleteAction) else if($_GET["action"] == "delete") { //Delete from database //Return result to jTable $jTableResult['Result'] = "OK"; } //Close database connection } catch(Exception $ex) { //Return error message $jTableResult['Result'] = "ERROR"; $jTableResult['Message'] = $ex->getMessage(); } ?>