92
« Último mensaje por Chewii en 04 de Junio de 2015, 20:26:51 pm »
Buenas amigos, espero esten bien, les escribo ya que encontre un tutorial acerca de un sistemita de registro de posiciones geograficas, y esta hecho con clases y queria probarlo, pero sinceramente, nose como corregir este error, y pensaba q uds me ayudaran; tengo un problema en el archivo de conexion con la base de datos, en los metodos de edicion de registros, me da un error de sintaxis, el codigo del archivo de conexion es este:
<?php
define("mysqlServer","localhost");
define("mysqlDB","mapas");
define("mysqlUser","root");
define("mysqlPass","0000");
class connectToDB
{
public static function addCompany( $company, $details, $latitude, $longitude, $telephone) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Insert INTO companies( company, details, latitude, longitude, telephone) VALUES( ?, ?, ?, ?, ?)");
$statement->bind_param('sssss', $company, $details, $latitude, $longitude, $telephone);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function updateCompany( $id, $details, $latitude, $longitude, $telephone) {
$db_connection = new mysqli( mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Update companies SET details = ?,latitude = ?,longitude = ?,telephone = ? where id = ?");
$statement->bind_param('ssssi', $details, $latitude, $longitude, $telephone, $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function deleteCompany($id) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Delete from companies where id = ?");
$statement->bind_param('i', $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function getCompaniesList() {
$arr = array();
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Select id, company, details, latitude, longitude, telephone from companies order by company ASC");
$statement->bind_result( $id, $company, $details, $latitude, $longitude, $telephone);
$statement->execute();
while ($statement->fetch()) {
$arr[] = ["id" => $id, "company" => $company, "details" => $details, "latitude" => $latitude, "longitude" => $longitude, "telephone" => $telephone];
}
$statement->close();
$db_connection->close();
return $arr;
}
public static function addStreet($street,$geo) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Insert INTO streets( name, geolocations ) VALUES( ?, ?)");
$statement->bind_param('ss', $street, $geo);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function updateStreet($id,$geo) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Update streets SET geolocations = ? where id = ?");
$statement->bind_param('si', $geo, $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function deleteStreet($id) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Delete from streets where id = ?");
$statement->bind_param('i', $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function getStreetsList() {
$arr = array();
$db_connection = new mysqli( mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Select id, name, geolocations from streets order by name ASC");
$statement->bind_result( $id, $name, $geolocations);
$statement->execute();
while ($statement->fetch()) {
$arr[] = [ "id" => $id, "name" => $name, "geolocations" => $geolocations];
}
$statement->close();
$db_connection->close();
return $arr;
}
public static function addArea($area,$geo) {
$db_connection = new mysqli(mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Insert INTO areas(name,geolocations) VALUES(?,?)");
$statement->bind_param('ss', $area,$geo);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function updateArea( $id, $geo) {
$db_connection = new mysqli( mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Update areas SET geolocations = ? where id = ?");
$statement->bind_param('si', $geo, $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function deleteArea($id) {
$db_connection = new mysqli( mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Delete from areas where id = ?");
$statement->bind_param('i', $id);
$statement->execute();
$statement->close();
$db_connection->close();
}
public static function getAreasList() {
$arr = array();
$db_connection = new mysqli( mysqlServer, mysqlUser, mysqlPass, mysqlDB);
$statement = $db_connection->prepare("Select id, name, geolocations from areas order by name ASC");
$statement->bind_result( $id, $name, $geolocations);
$statement->execute();
while ($statement->fetch()) {
$arr[] = [ "id" => $id, "name" => $name, "geolocations" => $geolocations];
}
$statement->close();
$db_connection->close();
return $arr;
}
}
?>
Y las lineas donde me da el error son estas:
<?php
$arr[] = ["id" => $id, "company" => $company, "details" => $details, "latitude" => $latitude, "longitude" => $longitude, "telephone" => $telephone];
$arr[] = [ "id" => $id, "name" => $name, "geolocations" => $geolocations];
$arr[] = [ "id" => $id, "name" => $name, "geolocations" => $geolocations];
?>
El problema se me da en los arreglos donde se guardan las actualizaciones, que me dice q hay un problema con un "["; espero me puedan ayudar, ya que me llamo mucho la atenciony quisiera saber como funciona. Saludos